Hi NareshG,
Based on my understanding, the root cause of the issue is that the data of the DataGridView is rebound and the cells of the DataGridView is recreated. Since the type of the column is DataGridViewTextBoxColumn, the new created cells would be of type DataGridViewTextBoxCell. So that we can only see the DataGridViewTextBoxCells.
These are my solutions:
1. We can reassign the cells just after we remove and insert the tab page as follows:
this.tabControl1.SuspendLayout();
this.tabControl1.TabPages.Remove(tabPage1);
this.tabControl1.TabPages.Insert(1, tabPage1);
tabControl1.ResumeLayout();
for (int i = 0; i < 5; i++)
{
if (i % 2 == 0)
this.dataGridView1.Rows[i].Cells[0] = new DataGridViewCheckBoxCell(false);
}
2. We can handle the DataBindingComplete event of the DataGridView and reassign the cells as follows:
void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
for (int i = 0; i < 5; i++)
{
if (i % 2 == 0)
this.dataGridView1.Rows[i].Cells[0] = new DataGridViewCheckBoxCell(false);
}
}
Let me know if this helps.
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.