We are using 2006.1 Windows Forms Grids. Is there any capability built in to the grids to sort a text(string) column as a number such that 1,2222,333,44 would sort properly as 1,44,333,2222?
This would be similar to the Excel (I know I shouldn't compare the WinGrids to Excel) function "Sort anything that looks like a number, as a number".
Does anyone have any advice on how to accomplish this?
Thanks for any advice!
The best way to get around is problem like this is not to store numbers as strings. Why not use a numeric data type?
If you can't do that, then you would have to create a custom SortComparer for the grid column.
Thank you very much for the reply Mike!
I agree whole heartedly with you but this particular column is our legacy system account numbers that have the form of a string as <5digits>.<2digits>, (ex: 28078.01, 98194.04). We are nearing the point where we hit 100000.01 and that will of course throw off the sort in our grids.
Short of modifying our existing all of our account numbers by placing a 0 in front of them, or actually converting this column to a number (although this is probably the right thing to do)....
Is there any chance you may be able to point me in the direction of where I might find an example of using the sort comparer?
Also, is there any possiblity that this functionality could be included in a future version of the grid? I would be happy to submit a feature request if you could familarize me with the procedure to do this!
I'm not sure if there are any samples. Check the Infragistics KB and search for SortComparer or IComparer.
SortComparers are pretty simple, though. What you do is create a class that implement IComparer. This interface has only one method: Compare. This method passes in two values and you pass back a value indicating which one is higher. In the case of the grid, the two values you get will be two UltraGridCell objects. So you get the Value of each cell (which will be a string), convert them to numberic values and then just return the compare method of the value of one on the other.
Great advice! I will give that a try thanks!
Thanks again Mike. Quite simple as you said. For those interested I found the example here:
http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.aspx?ArticleID=7695