Hi,
I'm using a DataTable as datasource of a RadGridView. The columns are automatically created.
I want to set some characteristics to the columns based on information that I get from a db, like header, visibility and column order. For the first two I'm using the AutoGeneratingColumn event and it's working perfectly. I haven't found a way to reorder the columns programmatically.
I tried the ReorderColumns(oldIndex, newIndex), but I wasn't able to get the oldIndex using grid.Columns.IndexOf(e.Column). It looks like grid.Columns doesn't have the complete list of generated columns.
Thanks in advance for your help!
Marco
I'm using a DataTable as datasource of a RadGridView. The columns are automatically created.
I want to set some characteristics to the columns based on information that I get from a db, like header, visibility and column order. For the first two I'm using the AutoGeneratingColumn event and it's working perfectly. I haven't found a way to reorder the columns programmatically.
I tried the ReorderColumns(oldIndex, newIndex), but I wasn't able to get the oldIndex using grid.Columns.IndexOf(e.Column). It looks like grid.Columns doesn't have the complete list of generated columns.
Thanks in advance for your help!
Marco
3 Answers, 1 is accepted
0
Accepted
Hi Marco,
You could try to use the Loaded event or the DataLoaded event of RadGridView.
Currently it is essential to use the Dispatcher if using the DataLoaded event due to a bug in ReorderColumns. A fix for this bug will be available with this Friday's Latest Internal Build.
Sincerely yours,
Milan
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
You could try to use the Loaded event or the DataLoaded event of RadGridView.
public partial class Window1 : Window |
{ |
public Window1() |
{ |
InitializeComponent(); |
this.playersGrid.ItemsSource = Club.GetPlayers(); |
this.playersGrid.DataLoaded += new System.EventHandler<System.EventArgs>(playersGrid_DataLoaded); |
this.playersGrid.Loaded += new RoutedEventHandler(playersGrid_Loaded); |
} |
void playersGrid_Loaded(object sender, RoutedEventArgs e) |
{ |
this.playersGrid.ReorderColumns(0, 1); |
} |
bool gridConfigured = false; |
// or |
void playersGrid_DataLoaded(object sender, System.EventArgs e) |
{ |
if (gridConfigured) |
return; |
this.Dispatcher.BeginInvoke(new Action(() => this.playersGrid.ReorderColumns(0, 1))); |
gridConfigured = true; |
} |
} |
Currently it is essential to use the Dispatcher if using the DataLoaded event due to a bug in ReorderColumns. A fix for this bug will be available with this Friday's Latest Internal Build.
Sincerely yours,
Milan
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Marco
Top achievements
Rank 1
answered on 25 Sep 2009, 09:29 PM
Milan,
Your suggestion worked perfectly, thank you. Though, I noticed the method ReorderColumns is slow, and it becomes an issue with many columns. Do you have a suggestion on how to speed up the ordering or is there any performance enhancement that you're planning on releasing anytime soon?
Thanks,
Marco
Your suggestion worked perfectly, thank you. Though, I noticed the method ReorderColumns is slow, and it becomes an issue with many columns. Do you have a suggestion on how to speed up the ordering or is there any performance enhancement that you're planning on releasing anytime soon?
Thanks,
Marco
0
Hello Marco,
With Q3 release we will introduce columns virtualization which will improve the performance of this method.
Best wishes,
Vlad
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
With Q3 release we will introduce columns virtualization which will improve the performance of this method.
Best wishes,
Vlad
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Paul
commented on 16 Mar 2023, 02:32 PM
Top achievements
Rank 2
Iron
Iron
Iron
This event fires before autogenerated columns are present.
Is there one that fires after the autogenerated columns have been added?
Is there one that fires after the autogenerated columns have been added?
Martin Ivanov
commented on 21 Mar 2023, 11:45 AM
Telerik team
There is no event that fires after all autogenerated columns are added. This said, there are different techniques to get the columns after they are generated, but the specific approach will depend on the user scenario. For example, you can use the Loaded event, if the data is assigned initially. Or you can use the AutoGeneratingColumns event of RadGridView and check the expected columns count in case you know this information. Or maybe, you can use the DataLoaded event with a Dispatcher to wait a bit for the columns to get generated.
Paul
commented on 21 Mar 2023, 11:51 AM
Top achievements
Rank 2
Iron
Iron
Iron
Thank you, I think the DataLoaded event will work for me.