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
220
Custom Sort Order with IEnumerable
posted

Hello, first post here.

 

Edit: "

The following code I'd like to use to sort one of my columns:

 

        Char[] myArr = new Char[1] { 'A', '!', 'B', 'C', '$' };

        IEnumerable<char> yourOriginalValues;

 

        yourOriginalValues = myArr;

 

        IEnumerable<char> result =

               yourOriginalValues.Where(c => Char.IsLetterOrDigit(c))

                    .OrderBy(c => c)

                    .Concat(yourOriginalValues.Where(c => !Char.IsLetterOrDigit(c)));

 

"

So far I have 

        private void ultraGridDaySheet_InitializeLayout(object sender, InitializeLayoutEventArgs e)

        {

            e.Layout.Override.HeaderClickAction = HeaderClickAction.ExternalSortMulti;

        }

  • 469350
    Offline posted

    Hi,

    If you want to sort a column in a custom order, then the thing to do it implement the IComparer interface and then set the SortComparer property on the column to an instance of the implementor.

    If you do a search on these forums for "IComparer" or "SortComparer", I'm sure you'll find a whole bunch of sample code.

    • 220
      posted in reply to Mike Saltzman

      Quick question, when I'm returning the value of:

       

      int IComparer.Compare(object x, object y)

      {

       

      }

       

      Is it returning the position for the string?

      • 17259
        Offline posted in reply to Wesley

        No. You need to return any number bigger than zero if x > y, or any number below zero if y > x, or zero if they are equal.