The following C# / asp.net code is taken here: Count checked checkboxes in a GridView
int totalCount = GridView1.Rows.Cast<GridViewRow>()
.Count(r => ((CheckBox)r.FindControl("chkSelect")).Checked);
// maybe: if(totalCount > 0)
UpdateProduct(totalCount);
The above code is asp.net solution.
I need WinForms solution.
Do you know WinForms version of the above code?
Please note that Linq solution is must. Loop solution is not accepted.
If you need to create dataGridView with CheckBoxColumn for testing needs you can use the following code.
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.Columns.Insert(0, new DataGridViewCheckBoxColumn());
dataGridView1.Rows.Add(4);
dataGridView1.Rows[0].Cells[0].Value = true;
dataGridView1.Rows[1].Cells[0].Value = false;
dataGridView1.Rows[2].Cells[0].Value = true;
dataGridView1.Rows[3].Cells[0].Value = false;
dataGridView1.Rows[4].Cells[0].Value = true;
}
Aucun commentaire:
Enregistrer un commentaire