http://www.telerik.com/help/silverlight/radgridview-how-to-show-hide-columns-outside-of-the-radgridview.html
If you show the DisplayIndex inside of the listbox, it is not updated when the columns are dragged and dropped into a different order in the grid.
5 Answers, 1 is accepted
I have tested the scenario you described but I was not able to reproduce the issue. I am sending you the sample project I used. Please take a look at it and let me know in case there is some misunderstandings according to your requirements.
Maya
the Telerik team
My mistake, it does appear to work in a listbox. But, it doesn't work inside of another grid. MainPage.xaml below:
<Grid x:Name="LayoutRoot" Background="White" DataContext="{StaticResource MyViewModel}"> <Grid.RowDefinitions> <RowDefinition Height="*"/> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <!--<ListBox ItemsSource="{Binding Columns, ElementName=playersGrid}" Grid.Column="0"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel> <CheckBox Content="{Binding Header}" IsChecked="{Binding IsVisible, Mode=TwoWay}" /> <TextBlock Text="{Binding DisplayIndex}" /> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox>--> <telerik:RadGridView ShowGroupPanel="False" AutoGenerateColumns="False" RowIndicatorVisibility="Collapsed" Grid.Column="1" ItemsSource="{Binding Columns, ElementName=playersGrid}"> <telerik:RadGridView.Columns> <telerik:GridViewCheckBoxColumn Header="Show?" UniqueName="IsVisible" DataMemberBinding="{Binding IsVisible}" AutoSelectOnEdit="True"></telerik:GridViewCheckBoxColumn> <telerik:GridViewDataColumn Header="Display Name" UniqueName="Header" DataMemberBinding="{Binding Header}"></telerik:GridViewDataColumn> <telerik:GridViewDataColumn Header="Name" UniqueName="UniqueName" DataMemberBinding="{Binding UniqueName}" IsReadOnly="True"></telerik:GridViewDataColumn> <telerik:GridViewDataColumn Header="Display Order" UniqueName="DisplayIndex" DataMemberBinding="{Binding DisplayIndex}"></telerik:GridViewDataColumn> </telerik:RadGridView.Columns> </telerik:RadGridView> <telerik:RadGridView Name="playersGrid" Grid.Column="2" ShowGroupPanel="False" ItemsSource="{Binding Players}" AutoGenerateColumns="False"> <telerik:RadGridView.Columns> <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}"/> <telerik:GridViewDataColumn DataMemberBinding="{Binding Number}"/> <telerik:GridViewDataColumn DataMemberBinding="{Binding Position}"/> <telerik:GridViewDataColumn DataMemberBinding="{Binding Country}"/> </telerik:RadGridView.Columns> </telerik:RadGridView> </Grid>Thank you,
Chad
The reason for this behavior is that the DisplayIndex-es properties of the columns are set a bit later and the grid holding the information for the columns is not updated. What you may do is to handle the ColumnReordered event of the playersGrid and call the Rebind() method for the second one.
I am sending you the updated version of the sample above so that you may test it directly.
Maya
the Telerik team
That updates the displayed values when the user drags and drops the columns in the playersGrid. But, what about when the user manually changes the DisplayIndex in the columnsGrid?
If I listen to the PropertyChanged event for each column in the playersGrid, it fires when the user changes IsVisible and Header values in the columnsGrid. But, it doesn't fire when the user changes the DisplayIndex.
<telerik:RadGridView Name="playersGrid" Grid.Column="2" ColumnReordered="playersGrid_ColumnReordered" ItemsSource="{Binding Players}" AutoGenerateColumns="False"> <telerik:RadGridView.Columns> <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" PropertyChanged="playersGrid_PropertyChanged" /> <telerik:GridViewDataColumn DataMemberBinding="{Binding Number}" PropertyChanged="playersGrid_PropertyChanged"/> <telerik:GridViewDataColumn DataMemberBinding="{Binding Position}" PropertyChanged="playersGrid_PropertyChanged"/> <telerik:GridViewDataColumn DataMemberBinding="{Binding Country}" PropertyChanged="playersGrid_PropertyChanged"/> </telerik:RadGridView.Columns> </telerik:RadGridView>"private void playersGrid_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName.Equals("DisplayIndex")) this.columnsGrid.Rebind(); }Thanks,
Chad
I have retested the case. However, once I change a value from the columnsGrid's DisplayIndex Column, the corresponding column changes its place in the playersGrid. The only issue I found is that the values in the DisplayIndex column are not updated properly, e.i. it may turns out that you have value "1" in that column for example . To resolve this you may handle the RowEditEnded event of the columnsGrid and again call its Rebind() method.
Let me know in case of any misunderstandings on this.
Maya
the Telerik team