Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
145 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...