Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
335
override sort when click on column header
posted

Hi,

  I am using ultra grid . In that grid one of the column is drop down

vli = vl.ValueListItems.Add(dr["ColorName"].ToString(), "     ");

vli.Appearance.BackColor = myColor;

In the drop down column ,i want to display only color and no text.Thats why i changed the

display member as "   ".

Now I want to sort the column.If I set the display member as "   ".I cant sort the column when

click on header because sorting is done based on display member text

Now I want to know how to override sort(),so that sorting is based on value member

 ie here name of the colour

 Is that possible?

plz help

thanks in advance

 

  • 1590
    Suggested Answer
    posted

    You can use a SortComparer to determine your own sort logic.

    How to use:

    E.g. column "Value" has string type but it's sorted as numeric.

    1)

    private class CustomComparer : IComparer
            {
                int IComparer.Compare(object x, object y)
                {
                    UltraGridCell xCell = (UltraGridCell)x;
                    UltraGridCell yCell = (UltraGridCell)y;

                    double val1;
                    double val2;
                    double.TryParse(xCell.Value.ToString(), out val1);
                    double.TryParse(yCell.Value.ToString(), out val2);

                    return val1.CompareTo(val2);
                }

     2. Set it to column:

               UltraGridColumn valueCol = grid_.DisplayLayout.Bands[0].Columns["Value"];
                valueCol.SortComparer = new CustomComparer();

     

    Thanks,  Alex.