Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
540
Changing or Binding to xamGrid Header Text
posted

I have an issue, that I think would be relatively straight forward, but I can't seem to make it work...

 

In short, I have a xamGrid, that is bound to some item source.  That source is a list of schedule data.  I simply want to change the headers to the dates based on the client's search.  So, I set them to some default like "Data1Text" through "Data7Text".  When the grid loads, I want it to change to something like "Sunday, 9/1/12" (first column header text) through "Saturday, 9/7/12" (last column header text).

 

I am using Template Columns.  I tried binding to the item source...to the view model... it never changes to the date.. below is a code snippet.  If that can't work, then I don't mind changing the column header text after the item source is updated...but I can't figure what event is used for that.  I am using MVVM and Prism framework, if that helps.

 

<ig:XamGrid HorizontalAlignment="Center" Name="xamGrdManageWeeklyPlanner" VerticalAlignment="Top"

ItemsSource="{Binding Path=WPRecords, Mode=TwoWay}" AutoGenerateColumns="False" MinWidth="890" MaxHeight="400"

SelectedCellsCollectionChanged="xamGrdManageWeeklyPlanner_SelectedCellsCollectionChanged"

SelectedRowsCollectionChanged="xamGrdManageWeeklyPlanner_SelectedRowsCollectionChanged"

MouseMove="xamGrdManageWeeklyPlanner_MouseMove" InitializeRow="xamGrdManageWeeklyPlanner_InitializeRow"

PropertyChanged="xamGrdManageWeeklyPlanner_PropertyChanged">

<ig:ContextMenuService.Manager>

<ig:ContextMenuManager>

<ig:ContextMenuManager.ContextMenu>

<ig:XamContextMenu Name="conWPMenuGrid" ItemClicked="XamContextMenu_ItemClicked" Opening="conMenuGrid_Opening">

<ig:XamMenuItem Header="Detail Manpower" />

<ig:XamMenuItem Header="Take Attendance" />

<ig:XamMenuItem Header="Modify Times" />

<ig:XamMenuItem Header="Modify Schedule" />

<ig:XamMenuItem Header="Approve Leave" />

<ig:XamMenuItem Header="Deny Leave" />

<ig:XamMenuItem Header="Modify Assignment Template" />

</ig:XamContextMenu>

</ig:ContextMenuManager.ContextMenu>

</ig:ContextMenuManager>

</ig:ContextMenuService.Manager>

<ig:XamGrid.Columns>

<ig:TemplateColumn Key="Employee" HeaderText="Employee" MaximumWidth="150">

<ig:TemplateColumn.ItemTemplate>

<DataTemplate>

<ContentPresenter Content="{Binding Employee}"/>

</DataTemplate>

</ig:TemplateColumn.ItemTemplate>

</ig:TemplateColumn>

<ig:TemplateColumn Key="Data1Text">

<ig:TemplateColumn.ItemTemplate>

<DataTemplate>

<ContentPresenter Content="{Binding Data1}"/>

</DataTemplate>

</ig:TemplateColumn.ItemTemplate>

</ig:TemplateColumn>

<ig:TemplateColumn Key="Data2Text">

<ig:TemplateColumn.HeaderTemplate>

<DataTemplate>

<TextBlock Text="{Binding}"/>

</DataTemplate>

</ig:TemplateColumn.HeaderTemplate>

<ig:TemplateColumn.ItemTemplate>

<DataTemplate>

<ContentPresenter Content="{Binding Data2}"/>

</DataTemplate>

</ig:TemplateColumn.ItemTemplate>

</ig:TemplateColumn>

<ig:TemplateColumn Key="Data3" HeaderText="Data3">

<ig:TemplateColumn.ItemTemplate>

<DataTemplate>

<ContentPresenter Content="{Binding Data3}"/>

</DataTemplate>

</ig:TemplateColumn.ItemTemplate>

</ig:TemplateColumn>

<ig:TemplateColumn Key="Data4" HeaderText="Data4">

<ig:TemplateColumn.ItemTemplate>

<DataTemplate>

<ContentPresenter Content="{Binding Data4}"/>

</DataTemplate>

</ig:TemplateColumn.ItemTemplate>

</ig:TemplateColumn>

<ig:TemplateColumn Key="Data5" HeaderText="Data5">

<ig:TemplateColumn.ItemTemplate>

<DataTemplate>

<ContentPresenter Content="{Binding Data5}"/>

</DataTemplate>

</ig:TemplateColumn.ItemTemplate>

</ig:TemplateColumn>

<ig:TemplateColumn Key="Data6" HeaderText="Data6">

<ig:TemplateColumn.ItemTemplate>

<DataTemplate>

<ContentPresenter Content="{Binding Data6}"/>

</DataTemplate>

</ig:TemplateColumn.ItemTemplate>

</ig:TemplateColumn>

<ig:TemplateColumn Key="Data7" HeaderText="Data7">

<ig:TemplateColumn.ItemTemplate>

<DataTemplate>

<ContentPresenter Content="{Binding Data7}"/>

</DataTemplate>

</ig:TemplateColumn.ItemTemplate>

</ig:TemplateColumn>

</ig:XamGrid.Columns>

<ig:XamGrid.SelectionSettings>

<ig:SelectionSettings CellClickAction="SelectCell" RowSelection="None" />

</ig:XamGrid.SelectionSettings>

<ig:XamGrid.EditingSettings>

<ig:EditingSettings AllowEditing="None" IsOnCellActiveEditingEnabled="False" IsMouseActionEditingEnabled="None" IsF2EditingEnabled="False" />

</ig:XamGrid.EditingSettings>

<ig:XamGrid.FilteringSettings>

<ig:FilteringSettings AllowFiltering="FilterMenu" FilteringScope="ColumnLayout" FilterMenuSelectionListGeneration="CompleteList"></ig:FilteringSettings>

</ig:XamGrid.FilteringSettings>

</ig:XamGrid>

  • 540
    Verified Answer
    posted

    Greetings all,

     

    Well, I guess this is what happens when you try to code late... i figured out the fix for this today, it was, as I thought, straight forward.  I had this code in my InitializeRow method for the grid.  Which was right...except I forgot the "_count++" at the end of the foreach... ::sigh:: It is working as expected now.

     

    private void xamGrdManageWeeklyPlanner_InitializeRow(object sender, InitializeRowEventArgs e)
            {
                int _count = 0;
                foreach(var c in e.Row.Columns)
                {
                    switch (_count)
                    {
                        case 0:
                            break;
                        case 1:
                            c.HeaderText = (this.DataContext as vmSchSchedule).Data1Text;
                            break;
                        case 2:
                            c.HeaderText = (this.DataContext as vmSchSchedule).Data2Text;
                            break;
                        case 3:
                            c.HeaderText = (this.DataContext as vmSchSchedule).Data3Text;
                            break;
                        case 4:
                            c.HeaderText = (this.DataContext as vmSchSchedule).Data4Text;
                            break;
                        case 5:
                            c.HeaderText = (this.DataContext as vmSchSchedule).Data5Text;
                            break;
                        case 6:
                            c.HeaderText = (this.DataContext as vmSchSchedule).Data6Text;
                            break;
                        case 7:
                            c.HeaderText = (this.DataContext as vmSchSchedule).Data7Text;
                            break;
                        default:
                            break;
                    }
                    _count++;
                }
            }