how to add the checkbox to the datagridview from coding

Innova picture Innova · Jun 17, 2010 · Viewed 67.7k times · Source

how to add the checkbox to the datagridview from coding in windows form.

i have a datatable with one column as value=true; and in another datatable i had settings for that column as value='Checkbox'

so if my value is true and checkbox is there the default datatable value cell has to be replaced with checkbox selected true. in that way

if the value is true by default it should be checked in that checkbox..

Answer

Rox picture Rox · Jun 17, 2010

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);