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 : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Always sort by one column

Thread ID:

Created:

Updated:

Platform:

Replies:

67912 Sep 4,2007 05:59 PM UTC Sep 5,2007 08:52 PM UTC WinForms 5
loading
Tags: Grouping
Haishi
Asked On September 4, 2007 05:59 PM UTC

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....


Haishi
Replied On 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?

Haishi
Replied On September 4, 2007 06:23 PM UTC

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

Ajish [Syncfusion]
Replied On 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.

Haishi
Replied On 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?

Ajish [Syncfusion]
Replied On 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.

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.

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

;