How can I get the value from the CheckBoxColumn using C # 3.0?
I can get the currently selected row like this:
private void DataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e){
//Cells[0] cause CheckBoxColumn is in that index (first column)
DataGridViewCheckBoxCell temp = (DataGridViewCheckBoxCell)dgv.Rows[e.RowIndex].Cells[0];
}
So now I want to get all the lines that have been checked by the user:
foreach (var row_ in DataGridView1.Rows.OfType<DataGridViewRow>().
Select(o => o.Cells.OfType<DataGridViewCheckBoxCell>().
Where(r => r.Value.Equals(true))).FirstOrDefault()){
}
I am getting null reference
from the debugger.
What am I doing wrong?
0
a source to share
2 answers
This is the answer, Hope helps (thanks to mquander for the idea.),
foreach (var _row in dgvpendientepago.Rows.OfType<DataGridViewRow>().
Where(o => o.Cells.OfType<DataGridViewCheckBoxCell>().
Any(r => r.EditedFormattedValue.Equals(true))))
{
// do stuff like the following :
lst4Pay.Add(new Cobranzaciaseguro
{
numeroatencion = Convert.ToInt16(_row.Cells[3].Value),
estado = 'P'
});
}
0
a source to share