Defines an interface to sort rows in GridControl.

Namespace: Dapfor.Wpf.Controls
Assembly: Dapfor.Wpf (in Dapfor.Wpf.dll) Version: 4.1.0.26317 (4.1.0.26317)

Syntax

C#
public interface ICustomSort
Visual Basic
Public Interface ICustomSort
Visual C++
public interface class ICustomSort
F#
type ICustomSort =  interface end

Remarks

In some cases sorting rules may be more complex than comparison of two objects that implement IComparable interface. Let's review an example of comparing credit ratings assigned by rating agencies. For example, Standard & Poor's sets long-term credit ratings from AAA to D with intermediate values (e.g. BBB+, BBB and BBB-). Simple row comparison yields incorrect sorting results. To solve this problem, you should implement ICustomSort.

 Copy imageCopy
class RatingComparer : ICustomSort 
{ 
    public int Compare(Row row1, Row row2, string fieldId, object value1, object value2, int defaultResult) 
    { 
        int result = defaultResult; 
        if (fieldId == "Rating") 
        { 
            string rating1 = (string) value1; 
            string rating2 = (string) value2; 
            if(!string.IsNullOrEmpty(rating1) && !string.IsNullOrEmpty(rating2)) 
            { 
                //compare two ratings: rating1 > rating2  =>  result is positive 
                //                     rating1 == rating2 =>  result = 0 
                //                     rating1 < rating2  =>  result is negative 

                //result = ... 
            } 
        } 
        return result; 
    } 
} 

grid.CustomSort = new RatingComparer();

See Also