Saqib Malick

Saqib Malick

  • NA
  • 23
  • 0

How to work with DataGridViewChecked Box Columns.

Jul 23 2010 11:39 AM

I am using Visual Studio 2005 , C#.

I have a datagridview with bind to a datasource, I have added three unbound Gridviewcheckedbox column in this gridview, I want that at run time these checked box work like a radio button, and at the run time when I click on any checked box all others checked box should be un-checked.

I have tried, but not success to do it, in the bellow code at the run time when I click 2nd time on any checked box, first checked box is not been un-checked. 

How should I do this.

My Code is her:

 private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
for (int i = 1; i <= dataGridView1.SelectedCells .Count ; i++)
{
if (Convert.ToBoolean(row.Cells[0].Value) == true)
{
row.Cells[1].Value = false;
row.Cells[2].Value = false;
}else if (Convert.ToBoolean(row.Cells[1].Value) == true)
{
row.Cells[0].Value = false;
row.Cells[2].Value = false;
}

else if (Convert.ToBoolean(row.Cells[2].Value) == true)
{
row.Cells[0].Value = false;
row.Cells[1].Value = false;

}
}
}


Answers (1)