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
110
Sorting a column other than the Group By Column
posted

Hello,

I have a scenario where i have a group by column which is a concatenation of a numeric value and a string value.

But when i try to sort the column, i want the result set to be sorted on the numeric value and not on the concatenation. 

There is a column in the grid which is hidden and which has the numeric values of the group by column.

I tried using the _AfterSortChange(object sender, BandEventArgs e) event and then adding the sort by

e.Band.SortedColumns.Add("NumericValues", sortIndicator == SortIndicator.Descending);

But then it removes the group by and just sorts by the numeric column. But i also want to keep the group by column.

How can i fix this scenario. Help needed please.

Thanks

Shailendra

Parents
No Data
Reply
  • 110
    Verified Answer
    posted

    I added the below class

    class MySortComparer : IComparer
    {

    public MySortComparer()
    {
    }

    public int Compare(object x, object y)
    {

    UltraGridCell xCell = (UltraGridCell)x;
    UltraGridCell yCell = (UltraGridCell)y;
    xCell = xCell.Row.Cells["NumericValues"];
    yCell = yCell.Row.Cells["NumericValues"];
    int val1 = Convert.ToInt16(xCell.Value);
    int val2 = Convert.ToInt16(yCell.Value);
    if (val1 < val2)
    return -1;
    else if(val1 == val2)
    return 0;
    else
    return 1;

    }

    }

    and then added the below line in the _AfterSortChange(object sender, BandEventArgs e) event.

    e.Band.Columns["NumericValuesAndStringValues"].SortComparer = new MySortComparer();

    It works fine. But is this right and is there a better way to do it.

    Thanks

    Shailendra

Children