Reputation: 53
I have a gridview control on my form.Its first column is checkboxcolumn and the other one textboxcolumn.I am populating Textbox columns with some string values coming from list
like this way
for (int i = 0; i < listeList.Count; i++)
{
dataGridView1.Rows.Add();
dataGridView1.Rows[i].Cells[1].Value = listeList[i];
}
What am i trying to do is to select all the checboxes in the gridview once the user click button How can I do this
Here is what I have tried
private void btnselectAll_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
// row.Cells[0].Value = "true";
//if (row.Cells[0].Value != ull)
//{
// if (Convert.ToBoolean(row.Cells[0].Value))
// {
// MessageBox.Show(row.Cells[1].Value.ToString());
// }
//}
}
}
Upvotes: 1
Views: 71
Reputation: 460068
Cast the appropriate cell to DataGridViewCheckBoxCell
:
for(int row = 0; row < this.dataGridView1.Rows.Count; row++)
{
var chkCell = dataGridView1[0, row] as DataGridViewCheckBoxCell;
// read:
bool isChecked = (bool)chkCell.EditedFormattedValue;
// assign:
chkCell.Value = true;
}
Upvotes: 1