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

查看:53
本文介绍了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);

对于整数类型值,它可以很好地工作,但是当数据包含双精度值时,它将不进行排序.

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

推荐答案

如果您使用的是绑定源,则只需将.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天全站免登陆