Is there a setting to tell the grid to sort differently? When I click the column to sort this is the outcome of an integer field. It seems as if it is only looking at the first digit in the number and not the number as a whole?
TIA,
-Ted
13
17
21
25
38
42
8
Hello Ted,
I believe that this is due to the fact that your coulmn's datatype is 'System.String' and not 'Int' or 'Decimal' for example. So the WinGrid control is comparing these 'digits' as strings actually. Please change the datatype to Int16 for example and try this again.
Thank you for the response Boris. This makes sense to me. My issue is I get an error saying cannot change datatype of a bound field. I don't think I'll be able to change the column datatype unless you know of an override I can do or a way around?
Thanks,
Ted
Hi Ted,
You can't change the data type of the grid column, you have to change the data type of the field in the data source.
Alternately, you could write your own SortComparer to compare strings as numeric values.
Hi Boris,
I ended up using an IComparer to achieve the results.
I wanted to know if you were able to solve your issue based on our suggestions? Which way did you take for this in the end?
I'm not using a SQL statement to pull from the database, I really don't have any control of how the datasource is being pulled into the grid.
If you cannot change the datatype in the datasource can't you just change the datatype in the SQL statement being used to pull out the data? That is what I do.
e.g. CAST(ISNULL(MyField,0) AS INT) as MyField etc
Of course you have to be sure there is no string values in there.
Thanks Mike, I might try the SortComparer since I cannot change the datatype in the datasource.