以编程方式循环遍历 DatagridView 并选中复选框
我有由数据表绑定的 DataGridView 我有相同的复选框。
我想导航或循环浏览 datagridview 并选中这些复选框,下面是我使用的语法。
foreach(DataGridViewRow dr in dgvColumns.Rows)
{
DataGridViewCheckBoxCell checkCell =
(DataGridViewCheckBoxCell)dr.Cells["CheckBoxes"];
checkCell.Value=1;
//Also tried checkCell.Selected=true;
//Nothing seems to have worked.!
}
I have DataGridView bound by a datatable i have checkboxes to the same.
I want to navigate or loop through the the datagridview and check mark these checkboxes ,Below is the syntax i use .
foreach(DataGridViewRow dr in dgvColumns.Rows)
{
DataGridViewCheckBoxCell checkCell =
(DataGridViewCheckBoxCell)dr.Cells["CheckBoxes"];
checkCell.Value=1;
//Also tried checkCell.Selected=true;
//Nothing seems to have worked.!
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
以下对我有用,它完美地检查了复选框:)
The following worked for me, it checked the checkboxes perfectly :)
如果它绑定到
DataTable
,您是否可以不处理模型(表)?DataGridView
是一个视图...尝试循环表中的行,设置值。 例如(如下) - 请注意,我不更新
DataGridView
- 只是更新DataTable
:If it is bound to a
DataTable
, can you not work on the model (the table) instead? TheDataGridView
is a view...Try looping over the rows in the table, setting the values. For example (below) - note that I don't update the
DataGridView
- just theDataTable
:大致如下:
Something along the lines of:
所选行的值不会传递到基础数据源,因此不会保存。 数据源是数据表。 它的数据网格视图问题。
the row that is selected its value do not get passed to the underlying datasource so do not get saved. the datasource is Datatable. Its problemof datagridview.
这看起来像是满足您的要求。 我对这一切都很陌生,如果我回答错误,我很抱歉。 只是想帮忙。
This looks like it does what you require. I'm new to all this so sorry if I have answered incorrectly. Just trying to help.