break

C#: Checkbox in a datagridview

I was trying to have a datagridview with a column that has a checkbox.

This is how I did it:

DataGridViewCheckBoxColumn ckbLotsOf = new DataGridViewCheckBoxColumn();
ckbLotsOf.Name = "chkLotsOf";
ckbLotsOf.HeaderText = "Lots of";
ckbLotsOf.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
dataGrid.Columns.Add(ckbLotsOf);

DataGridViewCheckBoxColumn creates the column with a checkbox. Your column needs a name, the text of the header of the column, autosize the column so it doesn’t take too much space, and then just add the column to the datagrid.

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

CAPTCHA Image
Reload Image