This is a migrated thread and some comments may be shown as answers.

[Solved] GridViewColumn.DisplayIndex does not fire PropertyChanged

5 Answers 427 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Chad
Top achievements
Rank 1
Chad asked on 26 Jan 2011, 06:18 PM
This is a great example to allow users to build views of data:
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

Sort by
0
Maya
Telerik team
answered on 31 Jan 2011, 06:31 PM
Hello Chad,

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.
 

Regards,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Chad
Top achievements
Rank 1
answered on 01 Feb 2011, 06:00 PM
Hi Maya,

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
0
Maya
Telerik team
answered on 03 Feb 2011, 11:12 AM
Hi 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.

Kind regards,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Chad
Top achievements
Rank 1
answered on 03 Feb 2011, 03:22 PM
Hi Maya,

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
0
Accepted
Maya
Telerik team
answered on 09 Feb 2011, 10:11 AM
Hello 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.
 

Kind regards,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
GridView
Asked by
Chad
Top achievements
Rank 1
Answers by
Maya
Telerik team
Chad
Top achievements
Rank 1
Share this question
or