Click here to Skip to main content
14,391,726 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello All ,

I have added datagridview(name dgvTestLoader) in windows form of C#. I have added columns collection as below
1) First column : column type : DataGridViewCheckBoxColumn
2) Second column : column type : DataGridViewTextBoxColumn

Below is the code which is adding row to this datagridview on click on button

DataGridViewRow row = new DataGridViewRow();
row.CreateCells(dgvTestLoader);
row.Cells[0].Value = CheckState.Checked;
row.Cells[1].Value = Txtname.text;
dgvTestLoader.Rows.Add(row);


There is no error to execute this code but after execution first row didn't display check box in datagridview.

Let me know correction in this code to change column type of first column as check box.

Thank you in advance.
Posted
Updated 17-Mar-19 21:56pm
v2
Rate this:
Please Sign up or sign in to vote.

Solution 1

First Create Column After Inseert ROws
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);
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100