如何从编码中将复选框添加到datagridview

Inn*_*ova 12 .net c# datatable datagridview windows-forms-designer

如何在Windows窗体中添加checkboxdatagridview编码.

我有datatable一个列,value=true; 而另一列datatable我有该列的设置为value='Checkbox'

所以,如果我的值为true,checkbox那么默认的数据表value单元格必须替换为checkbox选择的true.以这种方式

如果默认值为true,则应在该复选框中进行检查.

Rox*_*Rox 26

如果您打算添加一个带复选框的列:

DataGridViewCheckBoxColumn checkColumn = new DataGridViewCheckBoxColumn();
checkColumn.Name = "X";
checkColumn.HeaderText = "X";
checkColumn.Width = 50;
checkColumn.ReadOnly = false;
checkColumn.FillWeight = 10; //if the datagridview is resized (on form resize) the checkbox won't take up too much; value is relative to the other columns' fill values
dataGridView1.Columns.Add(checkColumn);
Run Code Online (Sandbox Code Playgroud)


Pra*_*mar 5

我认为在数据网格视图中添加复选框列的最简单方法是从 UI

              Step1 : Select the dataGrid at the UI
              Step2: Select Edit Column
              Step3: Click on the column name in edit Columns Window
              Step4:Select column type = "DataGridViewCheckBoxColumn"
              Step5: click ok
Run Code Online (Sandbox Code Playgroud)

附上一张截图 在此处输入图片说明

  • 我认为这是最好的方法! (2认同)