We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

GridTreeControl: Move a column

Thread ID:

Created:

Updated:

Platform:

Replies:

102452 Jan 31,2012 04:39 PM Feb 8,2012 01:34 PM WPF 1
loading
Tags: GridControl
anand rengarajan
Asked On January 31, 2012 04:39 PM

How can I move a column? Tried using the gridTreeControl.Model.MoveColumn without much success.



Clay Burch [Syncfusion]
Replied On February 8, 2012 01:34 PM

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);

};



CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;