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
4695
sorting in ultragrid
posted

Dear all,

I have the column (Datatype=system.string) in ultragrid. It is showing NA or decimal.

Actually the data is decimal (I have changed the value zero to be NA when showing in the grid.  0==> NA). But the sorting does not apply to decimal due to the datatype is string. The sorting is like below:

" 1 , 11, 2, 23, 3, 333, 4, NA "  in ascending order. How can I make sorting in decimal with NA ==0 but the showing in the grid is "NA"? Is it possible??

Parents
No Data
Reply
  • 5520
    Suggested Answer
    posted

    you have to create an IComparer and use it as the sortComparer of the grid

    here's a sample of the icomparer

     

    internal class CustomSortComparer : IComparer

            {

                internal CustomSortComparer()

                {

                    

                }

     

                int IComparer.Compare(object x, object y)

                {

     

                    // Passed in objects are cells. So you have to typecast them to UltraGridCell objects first.

                    UltraGridCell xCell = (UltraGridCell)x;

                    UltraGridCell yCell = (UltraGridCell)y;

     

                    //// Do your own comparision between the values of xCell and yCell and return a negative

                    //// number if xCell is less than yCell, positive number if xCell is greater than yCell,

                    //// and 0 if xCell and yCell are equal.

     

                }

            }

    hope this helps

     

Children