I'm having difficulty addressing the issue of a currency sorting problem within our in-house software package. The software in question is written using VB.NET and the values are contained within DataGridView, the relevant code is: SQLReader.Read() Code
and the result is: Value Column incorrectly sorted
There are more examples further down the column where values with commas inside them don't appear to sort correctly as well. How do I get them to sort?
I see your code is converting numeric currency values to a string and then displaying the string in the DataGridView
- that's your problem: this means the DataGridView will be performing lexicographic-ordering on the strings instead of numerical ordering (i.e. "21"
is ordered after "123"
because '2' > '1'
.
I don't know what the definition of m_DataRow
is, but it smells like you're using untyped DataSets, or perhaps a crudely created typed-DataSet but without any meaningful column names and types.
Unfortunately because your DataGridView looks to be bound to this m_dataRow
object you're stuck unless you can recreate it correctly (e.g. with actual column names and types). However if you're using untyped DataSets then just change your code to stop formatting currency values to string but instead provide the raw Decimal
value directly, and then use DataGridView's own column formatting to specify the "C" (for currency) format string.