如何使用 C# 3.0 从 CheckBoxColumn 获取值?
我可以通过这种方式获取当前选定的行:
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()){
}
我从调试器获取 null 引用
。
我究竟做错了什么?
I can get the current selected row in this way:
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 of the rows 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我怀疑你的做法是错误的,你真正想写的是:
但我不确定。
I suspect you're going about it wrong, and what you actually meant to write is this:
But I'm not certain.
这就是答案,希望有所帮助(感谢 mquander 的.任何想法):
This is the answer, Hopes helps (Thanks mquander for the .Any idea):