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

Always sort by one column

I need my grid to be always sorted by one column, then it can be sorted by addition columns at users' choice. When I load my grid, i did:

grid.TableDescriptor.SortedColumns.Clear();
this.grid.TableDescriptor.SortedColumns.Add("FixedSort", ListSortDirection.Descending);

And the grid is displayed correctly as expected. However, when user click on other column headers, the "FixedSort" column is removed from the SortedColumns collection. Then I tried to handle TableControlQueryAllowSortColumn event to adde the "FixedSort" column back into the collection, however after doing so, the sorting stopped working totally - i can only sort by descending order and i can only sort by one other column....


5 Replies

HA Haishi September 4, 2007 06:12 PM UTC

To correct my statement, the column is NOT removed from the SortedColumns collection, but "IsSorting" is set to false. However the property is not a public property so I don't know how I can reset it?


HA Haishi September 4, 2007 06:23 PM UTC

To correct above reply - the column is indeed removed.... I'm confused...


AJ Ajish Syncfusion Team September 5, 2007 12:05 AM UTC

Hi Stanley,

To make grid to be sorted by one column and then allow addition column to be sorted at user choice, you need to handle TableControlQueryAllowSortColumn event. In the event, you can cancel the default sorting and add the columns to be sorted. Here is the code for doing it,

>>>>>>
private void gridGroupingControl1_TableControlQueryAllowSortColumn(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridQueryAllowSortColumnEventArgs e)
{
e.AllowSort = false;

if (e.Column.Name != "FixedSort")
{
SortColumnDescriptorCollection columns = e.TableControl.TableDescriptor.SortedColumns;
if (columns.Contains(e.Column.Name))
{
if (columns[e.Column.Name].SortDirection == ListSortDirection.Ascending)
{
columns.Clear();
columns.Add("parentID", ListSortDirection.Descending);
columns.Add(e.Column.Name, ListSortDirection.Descending);
}
else
{
columns.Clear();
columns.Add("FixedSort", ListSortDirection.Descending);
columns.Add(e.Column.Name, ListSortDirection.Ascending );
}
}
else
{
columns.Clear();
columns.Add("FixedSort", ListSortDirection.Descending);
columns.Add(e.Column.Name, ListSortDirection.Ascending);
}
}
}
>>>>>>

and here is a sample for your reference
Sample: http://websamples.syncfusion.com/samples/Grid.Windows/I67912/main.htm

Kindly take a look at the sample and let me know if this helps in resolving your issue.

Regards,
Ajish.


HA Haishi September 5, 2007 07:41 PM UTC

So at any point of time, other than the default sorting column i can only have one more sorting column?


AJ Ajish Syncfusion Team September 5, 2007 08:52 PM UTC

Hi Stanley

Other than the default sorting column you can have more than one sorting columns. Here is a sample for your reference,

http://websamples.syncfusion.com/samples/Grid.Windows/F67912_1/main.htm

Kindly take a look and let me know if you have any other questions.

Regards,
Ajish.

Loader.
Live Chat Icon For mobile
Up arrow icon