【发布时间】:2018-12-07 03:55:34
【问题描述】:
我有一个 DataGridView,它有一个复选框列。我想要做的是,通过单击按钮,通过从这些行(id)获取某个列数据来更新复选框被选中的那些行,并将其发送到我拥有的更新 sql 命令。 首先,我使用数据表填充 datagridview,然后创建一个复选框列,其只读属性为 false,以便我可以单击它。 然后从按钮的 onclick 事件中,执行以下操作:
private void AnularBoton_Click(object sender, EventArgs e)
{
foreach datagridview row in datagrid {
if a certain column (checkbox) from that row is checked
then get the id from that row (id is the first column)
}
}
我会将这些 id 保存在一个数组中,然后一次性更新它们。
【问题讨论】:
-
那么为什么你的代码不起作用?
-
我想我很累找不到方法,但我做了一个类似于答案
List<int> segurosID = new List<int>(); foreach (DataGridViewRow dc in SegurosDataGridView.Rows) { if (dc.Cells["Anular"].Value != null) { if ((Boolean)dc.Cells["Anular"].Value == true) { segurosID.Add(Convert.ToInt32(dc.Cells["Seguro"].Value)); } } }的方法
标签: c# winforms datagridview