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.

Sort by a column - problem

Thread ID:

Created:

Updated:

Platform:

Replies:

63840 Jul 10,2007 02:04 PM Jul 10,2007 05:01 PM Windows Forms 2
loading
Tags: Grouping
Haishi
Asked On July 10, 2007 02:04 PM

Hi:

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 03:57 PM

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;
}
this.gridGroupingControl1.TableDescriptor.SortedColumns.Clear();
this.gridGroupingControl1.TableDescriptor.SortedColumns.Add("IsNew");
if (e.Column.Name != "IsNew")
this.gridGroupingControl1.TableDescriptor.SortedColumns.Add(e.Column.Name, direction);
}

Best Regards,
Haneef

Haishi
Replied On July 10, 2007 05:01 PM

Haneef:

Worked like a charm! Thanks a lot!

Stanley

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.

;