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

DisplayIndex problem

3 Answers 165 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tomas
Top achievements
Rank 1
Tomas asked on 29 Jun 2010, 11:36 AM
Hi,

I've got a RadGridView specified like this:

<telerik:RadGridView
    ItemsSource="{Binding MyDataSource}"
    AutoGenerateColumns="True"
    IsReadOnly="True"
    CanUserSelect="False"
    IsSynchronizedWithCurrentItem="False"
    SelectionMode="Multiple">
    <telerik:RadGridView.Columns>
      <telerik:GridViewSelectColumn />
    </telerik:RadGridView.Columns>
</telerik:RadGridView>

As you can see I have AutoGenerateColumns set to True but then I add a GridViewSelectColumn manually. Is it somehow possible using DisplayIndex attribute on columns or otherwise to specify the index of manually added columns when also having AutoGenerateColumns equal to True?

In this specific situation I would like to get the GridViewSelectColumn as the last column. I know I can manually add all the columns I want and then order them as I desire but as I'm using a special presentation entity class where I want all fields in that class to show up in the grid it would have been easy just to leave AutoGenerateColumns on.

Tomas

3 Answers, 1 is accepted

Sort by
0
Accepted
Yavor Georgiev
Telerik team
answered on 29 Jun 2010, 11:50 AM
Hello Tomas,

 Of course you can influence the ordering of the columns by setting the DisplayIndex property. However, the columns defined in XAML are created before the auto-generated ones, so you won't be able to specify the DisplayIndex there, because the maximum value of the DisplayIndex property is always the number of columns and at that time you will have only one column.

The solution is to handle the GridView's DataLoaded event. It fires after columns have been created. In the handler you can create and add the GridViewSelectColumn to the GridView's Columns collection. In this case, you won't even need to set the DisplayIndex property, because the column will be the last in the list at this point, but you can if you want it to appear at a different position.

Kind regards,
Yavor Georgiev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Tomas
Top achievements
Rank 1
answered on 29 Jun 2010, 01:01 PM
Hi Yavor,

I tried to add myGrid.Columns.Add(new Telerik.Windows.Controls.GridViewSelectColumn()); in DataLoaded event handler but that resulted in that I got as many selectcolumns as there was rows in the grid (at least I think so because there was lots of them)
 
I then tried the Loaded event instead and that seams to have done the trick. Is this the right approach?

Tomas
0
Accepted
Yavor Georgiev
Telerik team
answered on 29 Jun 2010, 01:07 PM
Hello Tomas,

 Of course, Loaded is the pen-ultimate loading event, so if it works for you, go ahead. I apologize for misleading you with the DataLoaded event.

Please don't hesitate to let me know if you have any further inquiries.

Sincerely yours,
Yavor Georgiev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Tomas
Top achievements
Rank 1
Answers by
Yavor Georgiev
Telerik team
Tomas
Top achievements
Rank 1
Share this question
or