Skip to content

Infragistics Community Forum / Desktop / Ultimate UI for Windows Forms / Sort a Ultragrid column by numeric value

Sort a Ultragrid column by numeric value

New Discussion
Tom
Tom asked on Jun 18, 2013 1:22 PM

the datasource for the ultragrid is SQL data rows. one of the columns “SortOrder” is int type in SQL.

when I click on the header of this column, it does the sorting, but it sorts the column treating the numbers as strings. The result is like 1 10 11 12 …..2 20 21…

How do I config the column setting to enable numeric sort?

Thank you,

Sign In to post a reply

Replies

  • 0
    Mike Saltzman
    Mike Saltzman answered on Sep 12, 2008 2:51 PM

    If the data is being sorted as strings, then it must be string data in the grid. Your data source must somehow be converting the ints into strings for some reason.

    • 0
      Campbell Wild
      Campbell Wild answered on May 29, 2013 6:15 PM

      I seem to have this problem too.  However, the underlying data is Integer, but I have a valuelist that converts the Integer value to String.  When I sort, it still sorts the data by display value (string) rather than by underlying data value.  Is there any way when I sort, it sorts by underlying value and not by display text?

      • 0
        Mike Saltzman
        Mike Saltzman answered on May 29, 2013 9:12 PM

        Hi,

        The grid sorts by what the user sees. But you can change this using a SortComparer on the column that examines the Value of each cell and ignores the ValueList.

        Or, an alternative would be to set the SortStyle on your ValueList to ValueListSortStyle.AscendingByValue or ValueListSortStyle.DescendingByValue. This will sort the items in the list and also let the grid know that the column should be sorted by value and not by the display text.

      • 0
        Campbell Wild
        Campbell Wild answered on May 30, 2013 7:55 AM

        Thanks Mike, as ever.  You da man…

      • 0
        Victor
        Victor answered on Jun 17, 2013 6:31 AM

        Hi Mike, I'm trying to do the same thing, but am confused about distinguishing between/specifying different values for display vs underlying value for a column.  I'm not using drop-downs, so not sure if "ValuerList" applies for me.  My data source is a ADO.Net DataSet; I want to show a textual format for a numeric value, but sort on the raw numeric value when the col header is clicked.  I believe I can use "SortComparer", but seems like all I could do is grab the display text and somehow try to get back to the raw numeric form for the comparison and I'd rather just store the discrete numeric/display values somewhere and directly reference in "SortComparer".  Thx!

      • 0
        Mike Saltzman
        Mike Saltzman answered on Jun 17, 2013 2:37 PM

        Hi,

        The SortComparer is an IComparer interface. This interface has only one method: Compare. The Compare method will pass you two values, x and y. In the case of a SortComparer, these two values will each be an UltraGridCell.

        So you can examine the cell and get any information you want from the that cell. In your case, you will probably want the cell.Value of each cell. And then you can return a value based on the comparison between those two values.

      • 0
        Victor
        Victor answered on Jun 18, 2013 1:20 PM

        Thx Mike, that's what I ended up with it works great.  I figured I needed a place to store the formatted (string) and raw (numeric) values and couldn't figure out how to do that with just the 1 "Value" cell property or bound dataset cell value, so I actually added a numeric sorting col (and hid it) and pointed to that col in the "Compare()" method I'd assigned to the "display" col version. 

        I had 1st gone down the path of using a 2-element string array ([0]=display value and [1]=raw numeric value) for the bound dataset col value that had display and raw properties so I could display the display value and sort on the raw numeric value.  I then tried using "BeforeSortChanged" event where tried to replace "SortedColumns" with the hidden numeric cols to sort on them that way.  I then went the route of using "ExternalSortSingle", where I left the raw numeric value in the underlying dataset, sorted that, then handled display via code.  Then I realized I could just refer to the hidden numeric cols for sorting as the subject of my compares in right in the "Compare()" method, so I went with that.

      • 0
        [Infragistics] Boris Toromanov
        [Infragistics] Boris Toromanov answered on Jun 18, 2013 9:24 AM

        Hello gmoran1,

        You could also take a look at the following link from our documentation, explaining the 'SortComparer' with examples:

        http://help.infragistics.com/Help/NetAdvantage/WinForms/2013.1/CLR4.0/html/Infragistics4.Win.UltraWinGrid.v13.1~Infragistics.Win.UltraWinGrid.UltraGridColumn~SortComparer.html.

        Please feel free to let me know if a question about our tool set comes up on your mind.

      • 0
        Victor
        Victor answered on Jun 18, 2013 1:22 PM

        Great thx Boris.  Yep, I found this page quite useful.

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Tom
Favorites
0
Replies
9
Created On
Jun 18, 2013
Last Post
12 years, 8 months ago

Suggested Discussions

Tags

Created by

Tom

Created on

Jun 18, 2013 1:22 PM

Last activity on

Feb 18, 2026 8:14 AM