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

GGC Sorting nothing/empty, large, small

Thread ID:

Created:

Updated:

Platform:

Replies:

130738 May 30,2017 03:01 PM UTC May 31,2017 09:55 AM UTC WinForms 1
loading
Tags: GridGroupingControl
Thomas
Asked On May 30, 2017 03:01 PM UTC

Hello,

I use a GridGroupingControl and in my first column in need numbers. I would like to sort this column from above with no number / empty field and than from large to small numbers. Is there a way to do this?

When I now sort with the default setting, than is sequence from large to small and than the empty fields.

Thanks for your support.
BR Thomas

Arulpriya Ramalingam [Syncfusion]
Replied On May 31, 2017 09:55 AM UTC

Hi Thomas, 

Thanks for your interest in Syncfusion products. 

We could able to understand your scenario and created a simple sample as per the reported scenario. In order to keep the empty cells at the top while applying descending sorting, the IComparer interface can be used. By using IComparer.Compare  method, you can customize the comparison of cell values. Please make use of below code and sample, 

Code snippet  
//Form() 
// set columnname to be sorted 
SortColumnDescriptor cd = new SortColumnDescriptor("ID"); 
this.gridGroupingControl1.TableDescriptor.SortedColumns.Add(cd); 
//set the sortdirection 
cd.SortDirection = ListSortDirection.Descending; 
//handles the empty cells at the top 
cd.Comparer = new CustomSort(); 
 
#region CustomSort 
public class CustomSort : IComparer 
{ 
    public int Compare(object x, object y) 
    { 
        if (x == null && y == null) 
            return 0; 
        // Exclude empty values for comparison 
        else if (x == DBNull.Value) 
        { 
            return 0; 
        } 
        else if (y == DBNull.Value) 
        { 
            return 0; 
        } 
        else 
        { 
            return ((IComparable)x).CompareTo(y); 
        } 
    } 
} 
#endregion 
 
 
 

Regards, 
Arulpriya 


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

;