Hi,
I suspect the answer to my question may lie with "IComparer" interface, but I can't get my head round how that works. Hopefully someone can help with a simple solution to my problem, or explain how to use IComparer for my scenario.
Within my bound datagridview, I have a column ("racenumber") which will only usually contain integers (1, 2, 3 etc) , but could potentially contain the odd non-numeric character (e.g., the numbers could be 1, 2, 3, 3A, 4 etc). Consequently, the values in this column are stored within the XML datasource as strings.
The problem comes when I try to sort the column, as because the values are strings, the numbers order incorrectly (100 comes before 50 etc). I have seen a lot of posts about this type of issue, but none seem to replicate my scenario and generally the suggestion is to change the datatype to integer, which I can't do, because of the potential for non-numeric characters.
I have considered adding a hidden, unbound column to the grid, which I would populate with a modified string representation of the number, including leading zeros, as I think that should then work. That column would then contain the values to sort when I click the header of the "racenumber" column. I really don't want to be displaying the leading zeros in the "racenumber" column if I can avoid it. But if I add this unbound column to the datagridview, how do I go about copying (and modifying) the entries in the "racenumber" column? I can create a function to add the leading zeros to the "racenumber" string, but how to get these figures into the pseudo column?
As always, any advice would be gratefully received.
Thanks,
Tim
I suspect the answer to my question may lie with "IComparer" interface, but I can't get my head round how that works. Hopefully someone can help with a simple solution to my problem, or explain how to use IComparer for my scenario.
Within my bound datagridview, I have a column ("racenumber") which will only usually contain integers (1, 2, 3 etc) , but could potentially contain the odd non-numeric character (e.g., the numbers could be 1, 2, 3, 3A, 4 etc). Consequently, the values in this column are stored within the XML datasource as strings.
The problem comes when I try to sort the column, as because the values are strings, the numbers order incorrectly (100 comes before 50 etc). I have seen a lot of posts about this type of issue, but none seem to replicate my scenario and generally the suggestion is to change the datatype to integer, which I can't do, because of the potential for non-numeric characters.
I have considered adding a hidden, unbound column to the grid, which I would populate with a modified string representation of the number, including leading zeros, as I think that should then work. That column would then contain the values to sort when I click the header of the "racenumber" column. I really don't want to be displaying the leading zeros in the "racenumber" column if I can avoid it. But if I add this unbound column to the datagridview, how do I go about copying (and modifying) the entries in the "racenumber" column? I can create a function to add the leading zeros to the "racenumber" string, but how to get these figures into the pseudo column?
As always, any advice would be gratefully received.
Thanks,
Tim