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

Custom sorting

Thread ID:

Created:

Updated:

Platform:

Replies:

69849 Nov 14,2007 05:35 PM UTC Nov 15,2007 11:33 AM UTC WinForms 3
loading
Tags: Grouping
Vladymyr
Asked On November 14, 2007 05:35 PM UTC

Hello there.

I need to create custom sorting.
I create custom comparer and set in SortColumnDescriptor.Comparer but in method Compare(x,y) I get values of record. We need to get records in Compare method. Please help.
int Capare(object x, object y)
{
Record r1 = (Record)x;
Record r2 = (Record)y;
}


Administrator [Syncfusion]
Replied On November 15, 2007 10:41 AM UTC

The SortComparer works on what ever is in the column.

One way to do something like you described (getting access to the underlying data in the SortComparer) would be to add an unbound column that holds references to the underlying data objects. Attached is a little sample that sorts the column named Col1 by using a custom comparer on an unbound column holding the underlying data objects (DataRowViews in the sample case since the datasource is a DataTable).




WindowsApplication32.zip

Vladymyr
Replied On November 15, 2007 11:09 AM UTC

Hello there.
It's works correctly. But add button in form it's not good. Is it possible to use standard sorting. For example if I click on the Column header the custom sorting appears.
And one more question.
I have in my grid more then 40 columns my custom sorting depends of sorting column. I dont want to creat more then 40 unbound columns for it. How can i do it?

I need for this behavior:
1. Click to any header column in grid
=> My custom sorting appears for this column.
Please help




Administrator [Syncfusion]
Replied On November 15, 2007 11:33 AM UTC

One way to hook the sorting up to clicking the column headers is to catch the TableControlCellClick event and if the click is on a column header, do the sort using code similar to what was in the button handler.

I do not think you need more than one unbound column. You can create different custom comparers to do the different types of sorting for a particular column. Here is that sample modified so that when you click on a header, it sorts the grid using a custom comparer based on values in the column to the right of the clicked column. It does this with a single unbound column.



WindowsApplication32_1.zip

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

;