CB
Clay Burch
Syncfusion Team
February 8, 2012 06:34 PM UTC
The order of the columns in a GridTreeControl is determined by the order that they appear in the gridTeeControl1.Columns collection.
If you explicitly create these column either through xaml or from code in the Load event, you can simple control the order by the order in which you add the columns.
If you let the GridTreeControl automatically populate this collection, then once the tree is displayed, you can just reaarange this collection and call InvalidateCells to refresh the display with the new column order. So, this would work, say from a button handler or menu item, once the tree has been displayed. Here is some code snippets.
//find a column by name
GridTreeColumn treeColumn = this.gridTreeControl1.Columns.Where(col => col.MappingName == "Extra1").First();
//move it to the first columns location, the expander column.
this.gridTreeControl1.Columns.Remove(treeColumn);
this.gridTreeControl1.Columns.Insert(0, treeColumn);
//this is need to refresh the display
this.gridTreeControl1.InternalGrid.InvalidateCells();
If you let the GridTreeControl automatically populate this collection, but you then want to tweak the column order before the initial display, the task becomes a little trickier because of the code flow during initialization. Here is code that should work to reorder a tree during Load that has had its Columns auto-populated.
this.gridTreeControl1.ModelLoaded += (s, e) =>
{
//set up frozen columns on the left
// value of 1 is rowheader (may be hidden)
// value of 2 is expand col (default setting)
//value of 3 will freeze first col to right of expander column
this.gridTreeControl1.Model.FrozenColumns = 3;
//set up frozen columns on the right
this.gridTreeControl1.Model.FooterColumns = 1; //freezes one column on right
//change the order of columns, but delay the code execution by using BeginInvoke
this.gridTreeControl1.Dispatcher.BeginInvoke(new Action(() =>
{
//find a column by name
GridTreeColumn treeColumn = this.gridTreeControl1.Columns.Where(col => col.MappingName == "Extra1").First();
//move it to the first columns location, the expander column.
this.gridTreeControl1.Columns.Remove(treeColumn);
this.gridTreeControl1.Columns.Insert(0, treeColumn);
//this is needed to refresh the display
this.gridTreeControl1.InternalGrid.InvalidateCells();
}), null);
};