根据数值对datagridview进行排序 [英] Sorting datagridview based on numeric values

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

问题描述



我有一个未绑定的数据网格视图。它拥有为学生获得的姓名和分数。



分数为12.25,12.35等。



我想要使用像

Hi,
I have an un-bound datagrid view. It holds Names and marks obtained for students.

Marks are like 12.25, 12.35 etc.

I want to use code like

dgvSM.Sort(dgvSM.Columns(2), System.ComponentModel.ListSortDirection.Descending) 





所以标记最少的那个位于顶部。但它不起作用。

datagridview正在根据文本进行排序,而不是以商业方式排序。



请帮助



我尝试了什么:



用Google搜索了很多,没有找到相关的内容



So the one with least marks comes at top. BUT it does not work.
The datagridview is being sorted based on text, not numercially.

Please help

What I have tried:

Googled alot, nothing found related

推荐答案

如果数据按字符串比较进行排序,那么因为当你填写它时你给了它字符串值。

不要 - 给它<改为code> double 值并使用Column DefaultCellStyle.Format属性格式化数据:如何:在Windows窗体DataGridView控件中格式化数据 [ ^ ]
If the data is being sorted by a string comparison, then that because when you filled it you gave it string values.
Don't - give it double values instead and use the Column DefaultCellStyle.Format property to format the data: How to: Format Data in the Windows Forms DataGridView Control[^]


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

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