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. Image for the cookie policy date

change column order

Is there a way we could have column order determined at runtime?  For instance, we define a grid with three columns, col1, col2 and col3 in that order.  But our user always changes the order to col2,col1,col3.  Is there a way we can have the column order by user specific?

5 Replies

SM Saravanan M Syncfusion Team March 18, 2015 11:40 AM UTC

Hi Henry,

Thank you for contacting Syncfusion support,

We have analyzed your query. GridDataControl provide method Add, Remove and Insert the column at runtime. So that you can change the columns order as you want.VisibleColumn.Add() method add the columns at last position and Insert method used to insert the column at specific location. Similarly Remove and RemoveAt method works accordingly.

In attached sample we have stored the column(Col1) and we have cleared it. We have insert the column(Col1) at First position , like this you can change the column order at runtime.

Code snippet[C#]:

private void Button_Click(object sender, RoutedEventArgs e)

{

var column = this.syncgrid.VisibleColumns[1];

this.syncgrid.VisibleColumns.RemoveAt(1);

this.syncgrid.VisibleColumns.Insert(0, column);

}

We have prepared the sample based on this and you can download it from below location,

Sample Location: GridDataControl_Sample.zip

We have a SfDataGrid control like GridDataControl. But compare to GridDataControl, SfDataGrid having a better performance and flexibility. SfDataGrid assists you to create entirely customizable and highly interactive features used to display and manipulate the huge amount of data. So, we suggest you to use SfDataGrid instead of GridDataControl.

You can also achieve the same requirement in SfDataGrid too. We have prepared a sample based on this and you can download it from below location,

Sample Location: SfDataGrid_Sample.zip

You can also refer the below documentation link to know more about SfDatagrid,

Documentation Link: http://help.syncfusion.com/ug/wpf/documents/overview6.htm

You can also refer the below comparison document between SfDataGrid and GridDataControl

Comparison Document: GridDataControl_SfDataGrid_Comparison.zip

Please let us know if you have any other queries,

Regards,

Saravanan.M



HH Henry Harris March 23, 2015 08:49 PM UTC

Thanks that is exactly what I needed


SC Saranya CJ Syncfusion Team March 24, 2015 06:32 AM UTC

Hi Henry,

Thank you for your reply. Please let us know if you require any other assistance on our controls.

Regards,

Saranya


SC sabrina c. February 2, 2016 03:22 PM UTC

Just a short comment, having this snippet of code in the Column section of the SFDataGrid documentation, or the KB would be nice.
It is in fact very useful if you want to build a grid and save the position of the columns on exit as a user setting
and show him the columns as he left them in his last session without much fuss :o)
thanks for writing it
Sabrina


SP Sowndaiyan Paulpandi Syncfusion Team February 3, 2016 01:48 PM UTC

Hi Sabrina,

Thanks for thr suggestions.

Currently we are working on SfDataGrid UG documentation and we will include this details in our documentation. In SfDataGrid you can retain the SfDataGrid old status using the Serialization and Deserialization support. You can refer the below UG link for know more about the this,

Link : http://help.syncfusion.com/wpf/sfdatagrid/serialization-and-deserialization#overview


Regards,


Sowndaiyan

Loader.
Live Chat Icon For mobile
Up arrow icon