在VB.NET中对货币进行排序 [英] Sorting currency in VB.NET

查看:69
本文介绍了在VB.NET中对货币进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在解决内部软件包中的货币分类问题时遇到了困难.有问题的软件是使用VB.NET编写的,其值包含在DataGridView中,相关代码为: SQLReader.Read()代码

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

,结果是:值列排序不正确

此列下还有更多示例,其中包含逗号的值似乎也无法正确排序.我如何让它们排序?

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?

推荐答案

我看到您的代码将数字货币值转换为字符串,然后在 DataGridView 中显示该字符串-这是您的问题:表示DataGridView将对字符串执行字典顺序而不是数字顺序(即,在"123" 之后对"21" 进行排序,因为'2'>'1'.

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'.

我不知道 m_DataRow 的定义是什么,但是它闻起来像是您正在使用无类型的DataSet,或者也许是一个粗略创建的typed-DataSet,但是没有任何有意义的列名和类型.

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.

不幸的是,由于您的DataGridView看起来已绑定到此 m_dataRow 对象,除非您可以正确地重新创建它(例如,使用实际的列名和类型),否则该对象将被卡住.但是,如果您使用的是无类型的数据集,则只需更改代码以停止将货币值格式化为字符串,而是直接提供原始的 Decimal 值,然后使用DataGridView自己的列格式来指定"C"(货币)格式字符串.

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.

这篇关于在VB.NET中对货币进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆