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

[Solved] Control Ordering of Columns

0 Answers 110 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.
Jeffrey Hare
Top achievements
Rank 1
Jeffrey Hare asked on 07 Mar 2011, 02:17 AM
Hello,

I'm using RadGridView bound to a WCF RIA services EntitySet<> Collection in an MVVM-Lite based application.

I'm handling the AutoGeneratingColumn event to skip certain columns at load time that shouldn't be shown or edited.

I have a column header context menu set up to allow hiding/showing the remaining columns that actually got added to the grid.

What I don't know how to do is to control the column ordering at load time, or later (if the customer wants to quickly reset the column order to some default).

Any guidance here would be greatly appreciated!
Thanks,
-Jeff

[Edit:]
Well, no sooner than I write this the answer becomes obvious...  Hope this helps someone else...

private void GeneratingColumn(Telerik.Windows.Controls.GridViewAutoGeneratingColumnEventArgs e)
{
    // eventually, we'll load the preferred columns from preferences.
     
    // We define a List<string> of columns that should never go in the grid.
    // If in this list, cancel the add of this column
    e.Cancel = HideColumns.Contains(e.Column.UniqueName);
      
    // We define a List<string> in the order that they should be shown. 
    if (ShowColumns.Contains(e.Column.UniqueName)) 
         e.Column.DisplayIndex = ShowColumns.IndexOf(e.Column.UniqueName); 
}

Tags
GridView
Asked by
Jeffrey Hare
Top achievements
Rank 1
Share this question
or