Winforms 如何使用C3.0从CheckBoxColumn中获取值?

Winforms 如何使用C3.0从CheckBoxColumn中获取值?,winforms,datagridview,lambda,Winforms,Datagridview,Lambda,我可以通过以下方式获取当前选定行: 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

我可以通过以下方式获取当前选定行:

 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];
}
因此,现在我想获得用户检查过的所有行:

 foreach (var row_ in DataGridView1.Rows.OfType<DataGridViewRow>().
                                        Select(o => o.Cells.OfType<DataGridViewCheckBoxCell>().
                                         Where(r => r.Value.Equals(true))).FirstOrDefault()){

}
我从调试器获取空引用


我做错了什么?

我怀疑你做错了,你真正想写的是:

foreach (var row_ in
    DataGridView1.Rows.OfType<DataGridViewRow>().
    Where(o => o.Cells.OfType<DataGridViewCheckBoxCell>().
    Any(r => r.Value.Equals(true))))
{

}

但我不确定。

这是答案,希望有助于感谢mquander的帮助。有什么想法:

        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'
          });
        }