how to add the checkbox to the datagridview from coding
74,228
Solution 1
If you meant to add a column with checkboxes:
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);
Solution 2
I think the easiest way to add Checkbox column in datagrid view is from the 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
Solution 3
For these kind of questions you can just add the control through the designer and see what Visual Studio did in the code behind file.
Solution 4
Assuming that you mean how to add a checkbox column to a DataGridView
dynamically:
DataGridViewCheckBoxColumn col = new DataGridViewCheckBoxColumn();
... // set properties as needed here
dataGridView1.Columns.Add(col);
Comments
-
Innova over 4 years
how to add the
checkbox
to thedatagridview
from coding in windows form.i have a
datatable
with one column asvalue=true;
and in anotherdatatable
i had settings for that column asvalue='Checkbox'
so if my value is true and
checkbox
is there the default datatablevalue
cell has to be replaced withcheckbox
selected true. in that wayif the value is true by default it should be checked in that checkbox..