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

DisplayIndex of RadGridView column not saved correctly

4 Answers 240 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Alexander
Top achievements
Rank 1
Alexander asked on 12 Sep 2011, 03:30 PM
Hello everyone,
In my application I have 2 RadExpanders. Each RadExpander contains a RadGridView. One RadExpander has IsExpanded set to TRUE other is set to FALSE. Also I am saving RadGridViews settings, using your example. The problem is that for the RadGridView that is placed in RadExpander with IsExpanded set to FALSE, DisplayIndex for all grid's columnsis set to -1, not to the corresponding oreder of the column.
Below is the code I use:
<UserControl x:Class="GridSettings.MainPage"
    xmlns:local="clr-namespace:GridSettings"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
 
    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <StackPanel>
            <telerik:RadExpander Margin="2"  IsExpanded="False" Header="Not Visible Grid">
                <telerik:RadExpander.Content>
                    <telerik:RadGridView local:RadGridViewSettings.SaveSettings="True" Name="hiddenGrid">
                        <telerik:RadGridView.Columns>
                            <telerik:GridViewDataColumn Header="Name" />
                            <telerik:GridViewDataColumn Header="Surname" />
                        </telerik:RadGridView.Columns>
                    </telerik:RadGridView>
                </telerik:RadExpander.Content>
            </telerik:RadExpander>
            <TextBlock Text="Column index"></TextBlock>
            <ListBox Margin="2"  ItemsSource="{Binding ElementName=hiddenGrid, Path=Columns}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding Header}" Margin="2" />
                            <TextBlock Text="Display Index:" Margin="2" />
                            <TextBlock Text="{Binding DisplayIndex}" Margin="2" />
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </StackPanel>
 
        <StackPanel Grid.Row="1">
            <telerik:RadExpander Margin="2"  IsExpanded="True" Header="Visible Grid">
                <telerik:RadExpander.Content>
                    <telerik:RadGridView local:RadGridViewSettings.SaveSettings="True" Name="visibleGrid">
                        <telerik:RadGridView.Columns>
                            <telerik:GridViewDataColumn Header="Name" />
                            <telerik:GridViewDataColumn Header="Surname" />
                        </telerik:RadGridView.Columns>
                    </telerik:RadGridView>
                </telerik:RadExpander.Content>
            </telerik:RadExpander>
            <TextBlock Text="Column index"></TextBlock>
            <ListBox Margin="2" ItemsSource="{Binding ElementName=visibleGrid, Path=Columns}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding Header}" Margin="2" />
                            <TextBlock Text="Display Index:" Margin="2" />
                            <TextBlock Text="{Binding DisplayIndex}" Margin="2" />
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </StackPanel>
         
    </Grid>
</UserControl>
It seems that settings are saved correctly just for visible in UI grid.

Thank you
Best regards
Alexandru 

4 Answers, 1 is accepted

Sort by
0
Tsvyatko
Telerik team
answered on 15 Sep 2011, 01:08 PM
Hello Alexander,

 Thank you for sharing information about the scenario. Unfortunately, the display indexes of the columns are not initialized, since the grid is not loaded yet. The RadGridView uses lazy initialization of processing its itemssource and loading template.

In your scenario, I can suggest to force gridview initatialization using the following line:

SampleGrid.ApplyTemplate();

Regards,
Tsvyatko
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Alexander
Top achievements
Rank 1
answered on 15 Sep 2011, 01:59 PM
Hello,
I have tested  the suggestion you gave, but it doesn't solve the problem.
I have put MyGrid.ApplyTemplate();  in MainPage constructor, but there is no effect. The grid is initialized but whith wrong DisplayIndex values. Even if I reset the grid's settings the problem still occurs.
0
Tsvyatko
Telerik team
answered on 21 Sep 2011, 07:52 AM
Hi Alexander,

 Please excuse us that the previous solution was not helpful in your scenario.

In this case I can suggest to use this code to force grid initialization:

hiddenGrid.ApplyTemplate();
hiddenGrid.Measure(new Size(0,0));

Please find the attachment demonstrating this approach.
Let us know if this fits in our case. Regards,
Tsvyatko
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Alexander
Top achievements
Rank 1
answered on 22 Sep 2011, 08:18 AM
Hello,
Thank you for the provided solution, it is quite good and it solve the problem. It is good for applications where are a few grids and when working in code-behind file. In our application we use a lot of grids, so this means that I have to use the suggested code for each grid that brings a lot of duplication. So as a workaround for this issue I think it will be better to check the column's DisplayIndex, and if it has a bad value(< 0) replace it with index value of the column in Grid.Columns collection, this can be done with one line of code (Grid.Columns.IndexOf(column)) in one place (Grid Settings file, save method) for all grids.
Tags
GridView
Asked by
Alexander
Top achievements
Rank 1
Answers by
Tsvyatko
Telerik team
Alexander
Top achievements
Rank 1
Share this question
or