Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add the checkbox to the datagridview from coding

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..

like image 574
Innova Avatar asked Jun 17 '10 11:06

Innova


3 Answers

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);
like image 107
Rox Avatar answered Oct 10 '22 17:10

Rox


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

Attached a snaphot enter image description here

like image 7
Praveer Kumar Avatar answered Oct 10 '22 17:10

Praveer Kumar


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.

like image 3
Carra Avatar answered Oct 10 '22 18:10

Carra