简体   繁体   English

C#Datagridview不对Checkbox列进行排序

[英]C# Datagridview does not sort Checkbox column

When I bind a Linq-to-sql query to a datagridview (using a BindingSource in between), the columns are sortable by default. 当我将Linq-to-sql查询绑定到datagridview(在其间使用BindingSource)时,默认情况下列可以排序。 However, this does not seem to be the case for boolean types. 但是,布尔类型似乎不是这种情况。 For these the datagridview uses Checkbox columns, but when I click on the header nothing happens. 对于这些,datagridview使用Checkbox列,但是当我点击标题时没有任何反应。 Solution anyone? 解决任何人?

In VS2012 in the designer you can also set the SortMode. 在设计器的VS2012中,您还可以设置SortMode。

Right-click on the DataGridView and go to "Edit Columns". 右键单击DataGridView并转到“编辑列”。

There's a drop-down for SortMode with a choice of NotSortable, Automatic, and Programmatic. SortMode有一个下拉列表,可选择NotSortable,Automatic和Programmatic。

It appears that the default for most columns is Automatic, but for checkboxes (boolean) columns the default is NotSortable. 似乎大多数列的默认值为Automatic,但对于checkboxes(boolean)列,默认值为NotSortable。

这会有帮助吗?

dgv1.Columns["Colname"].SortMode = DataGridViewColumnSortMode.Automatic;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM