Click here to Skip to main content
16,012,843 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello friends
I m adding columns in gridview dynamically which is working perfectly fine.
but i also want to add checkbox before adding columns in grid view which is not dynamic.
can anyone help me how to add checkbox in gridview as first column and then all columns will be addded dynamically.
Thanks
Posted

I assume you are using WinForms and you are referring to the DataGridView(you should tag your question with the UI framework you are using)then you can add the first column using the editor. There should be a small arrow at the top right on the DataGridView which allows you to add and edit columns in the designer.

Hope this helps
 
Share this answer
 
The binding source should have a boolean property, which will be bound to a check box, that determines whether or not the other dynamically created properties are displayed.
 
Share this answer
 
I haven't done that in C# in a while, but in VB it would be something like this (if I remember right the C# method is pretty close)

Dim gridCheck As New DataGridViewCheckBoxColumn

        With gridCheck
            .HeaderText = ""
            .Name = "gridCheck"
            .Width = 30
            .HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        End With

dgvWhatEver.Columns.Insert(0, gridCheck)
 
Share this answer
 
Comments
miligupta123 20-Jun-11 8:41am    
Thanks A Lot.I appreciate your solution.but i dont know VB.so cant able to implement in c#.
MacRaider4 20-Jun-11 8:55am    
really?
<pre>
DataGridViewCheckBoxColumn gridCheck = new DataGridViewCheckBoxColumn();

gridCheck.HeaderText = "";
gridCheck.Name = "gridCheck";
gridCheck.Width = 30;
gridCheck.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;

dgvTest.Columns.Insert(0, gridCheck);</pre>

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