DataGridView以编程方式排序 [英] DataGridView Sort Programmitically

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

问题描述

我创建了我从DataGridViewTextBoxColumn类派生的自定义DataGridViewNumericTextBoxColumn。

I have created my custom DataGridViewNumericTextBoxColumn derived from DataGridViewTextBoxColumn class.

当我调用

this.HeaderDataGridView .Sort = Sort.Programmiticaly;
this.HeaderDataGridView.Sort(this.HeaderDataGridView.Columns [Utility.HEAD_X],ListSortDirection.Ascending);

this.HeaderDataGridView.Sort = Sort.Programmiticaly; this.HeaderDataGridView.Sort(this.HeaderDataGridView.Columns[Utility.HEAD_X], ListSortDirection.Ascending);

它对整型类型值正常工作,但当数据包含双重值时,它不排序。

It is working fine for integer type values but when the data contain double values it don't sort.

谢谢,
Ashish

Thanks, Ashish

推荐答案

如果您使用绑定源,可以将.Sort属性设置为要排序的列的名称。例如:

If you are using a binding source, you can simply set the .Sort property to the name of the column you want to sort on. For example:

myBS = new BindingSource();
myBS.DataSource = DataSet.MY_TABLE;
myBS.Sort = "MY_COLUMN";
myGrid.DataSource = myBS;

这篇关于DataGridView以编程方式排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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