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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Sort by a column - problem

Thread ID:





63840 Jul 10,2007 06:04 PM UTC Jul 10,2007 09:01 PM UTC WinForms 2
Tags: Grouping
Asked On July 10, 2007 06:04 PM UTC


In my grouped grid i want to keep the data to be always sorted by one of the columns, say, "IsNew" column. Then I'd like allow user to sort by other columns as they wish (the "IsNew" column is hidden). However I found whenever user clicks on the column header to change sorting, the SortedColumns collection is cleared. To fix this, I tried to handle TableDescriptor.SortedColumns.Changed event and add the column back:

void SortedColumns_Changed(object sender, ListPropertyChangedEventArgs e)
if (!this.grid.TableDescriptor.SortedColumns.Contains("IsNew"))
this.grid.TableDescriptor.SortedColumns.Insert(0, new SortColumnDescriptor("IsNew", ListSortDirection.Ascending));

After this change I found when i click on any colum header to sort the data, the colum keeps in ascending order. I trace down the event and found out that no matter how many times i click the column header the ListSortDirection is alwasy Ascending, instead of flipping between ascending/descending as before. Any ideas?

haneefm [Syncfusion]
Replied On July 10, 2007 07:57 PM UTC

Hi Stanley,

This can be achieved by handling a the TableControlQueryAllowSortColumn event handler and set the e.AllowSort property to false to cancel default grid sorting for the required columns. Please try the following code snippet and let me know if this helps

void gridGroupingControl1_TableControlQueryAllowSortColumn(object sender, GridQueryAllowSortColumnEventArgs e)
e.AllowSort = false;
ListSortDirection direction = ListSortDirection.Ascending;
if (this.gridGroupingControl1.TableDescriptor.SortedColumns.Contains(e.Column.Name))
direction = this.gridGroupingControl1.TableDescriptor.SortedColumns[e.Column.Name].SortDirection;
direction = direction == ListSortDirection.Descending ? ListSortDirection.Ascending : ListSortDirection.Descending;
if (e.Column.Name != "IsNew")
this.gridGroupingControl1.TableDescriptor.SortedColumns.Add(e.Column.Name, direction);

Best Regards,

Replied On July 10, 2007 09:01 PM UTC


Worked like a charm! Thanks a lot!



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.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon 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.Close Icon