对DataGridView数据进行数字排序 [英] Sort DataGridView Data Numerically

查看:106
本文介绍了对DataGridView数据进行数字排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个未绑定的DataGridView,带有多个列(10).单击按钮时,我以编程方式向其中添加数据.第一列包含以毫秒为单位的持续时间(1000 = 1sec).每次将一行数据添加到dataGridView时,我都需要它根据column1(ms)的值来更新行的排序列表.
我正在使用DataGridView1.listSortDirection(升序),但是当我需要将它们从最小(顶部)到最大(底部)排序时,它会将它们排序为字符串而不是整数.有人提到设置列的dataValueType,但是我是编程的新手,也不知道如何执行此操作.任何帮助将不胜感激.

I have an unbound DataGridView w/ multiple columns(10). I add data to it programatically when a button is clicked. The first column contains durations in milliseconds(1000 = 1sec). Each time a row of data is added to the dataGridView, I need it to update the sort list of the rows depending on the value of column1(ms).
I''m using DataGridView1.listSortDirection(ascending), but it sorts them as strings instead of integers, when I need them to be sorted from least(top) to greatest(bottom). Someone mentioned setting the column''s dataValueType, but I''m a novice at programming, and have no idea how to do this. Any help would be greatly appreciated.

推荐答案

请参阅此帖子
如何对DataGridView列进行数字排序? [ ^ ]
我认为这可能会有所帮助.
Please see this post
How to sort a DataGridView Column numerically?[^]
I think it may be helpful.


DataValueType是正确的-检查包含毫秒的字段的类型.
如果类型为字符串,则排序将基于字符串.
如果类型是数字,则排序将基于数字.
DataValueType is correct - check the type of the field that contains millisecond.
If the type is string sorting would be based on strings.
If the type is numeric, the sort would be based on numbers.


这篇关于对DataGridView数据进行数字排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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