Click here to Skip to main content
15,878,970 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have created datagridview dynamically with check box column,once i refresh my datagrid its removes all data except checkbox column,below code for adding checkbox column in datagrid

C#
DataGridViewCheckBoxColumn chk = new DataGridViewCheckBoxColumn();
dataGridView1.Columns.Add(chk);
chk.HeaderText = "Check Data";
chk.Name = "chk";
 int count = dataGridView1.Rows.Count;
 for (int i = 0; i < count; i++)
 {
     dataGridView1.Rows[i].Cells[12].Value = false;
 }

and below code for clearing my datagrid,if i try to add new data in datagridview after refresh still old check box exists and it keeps adding one more checkbox column.

C#
dataGridView1.Rows.Clear();
dataGridView1.Refresh();

any suggestion???
Posted
Updated 26-Aug-14 17:58pm
v2

Clear the data source first and , bind cleared data source to the grid view when you want to clear.
 
Share this answer
 
Comments
Archana Palani 27-Aug-14 0:36am    
i have tried to add databind but i got a problem here,i am using usercontrol which is not accepting the system.web.ui namespace,can u please guide me to overcome this?
i tried as follows

C#
dataGridView1.Columns.RemoveAt(12);


i mentioned the index of checkbox and its worked.

Thanks All
 
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