简体   繁体   English

如何在 DataGrid 控件中添加复选框列?

[英]How to add CheckBox Column in DataGrid Control?

I have tried to add a CheckBox to a DataGrid (.Net 2.0, Not the DataGridView), but isn't working.我曾尝试将CheckBox添加到DataGrid (.Net 2.0,不是 DataGridView),但不起作用。 What am I doing wrong?我究竟做错了什么?
My attempt:我的尝试:

DataColumn colNewDGCol = new DataColumn();
colNewDGCol.DataType = System.Type.GetType("System.Boolean");
colNewDGCol.DefaultValue = false;
colNewDGCol.ColumnName = ("ck");
ds.Columns.Add(colNewDGCol);

You need to set the cell template of the column you wish to become checkbox column.您需要设置要成为复选框列的列的单元格模板。

DataGridViewColumn col1 = new DataGridViewColumn();
DataGridViewCell cell = new DataGridViewCheckBoxCell();
col1.CellTemplate = cell;

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

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