Click here to Skip to main content
15,891,680 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have this code to add a checkbox to the 3rd column of the datagrid, but the index of this columns is 0 and not 3. Does anyone understand this error and how to fix it? Thanks

C#
public void bloqselect()
       {
           DataGridViewCheckBoxColumn chkSelect = new DataGridViewCheckBoxColumn();
           chkSelect.Selected = false;
           chkSelect.HeaderText = "Bloqueador";
           chkSelect.Name = "chkSelect";
           grid_lic.Columns.Insert(3, chkSelect);

           if (chkSelect.Selected == true)

               bloqueador = 1;

           else
               bloqueador = 0;
       }
Posted
Comments
Suvendu Shekhar Giri 20-Dec-15 20:43pm    
Nothing looks wrong with your code. Are there any other operations with the grid after this method?

1 solution

The column count starts at 0 which means that the index of the third column will be 2.

Try
C#
grid_lic.Columns.Insert(2, chkSelect);
 
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