简体   繁体   中英

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. 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. Solution anyone?

In VS2012 in the designer you can also set the SortMode.

Right-click on the DataGridView and go to "Edit Columns".

There's a drop-down for SortMode with a choice of NotSortable, Automatic, and Programmatic.

It appears that the default for most columns is Automatic, but for checkboxes (boolean) columns the default is NotSortable.

这会有帮助吗?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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