Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
5.00/5 (1 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

C#
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 20:56pm
v2

 
Share this answer
 
First Create Column After Inseert ROws
C#
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);
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900