我有一个奇怪的问题。基本上我有一个datagridview 和一个按钮。当我单击此按钮时,它会检查第 1 列值的所有行 - 复选框列。然后根据当前的情况将其设置为 true / false。
没关系。
但是,我有另一个按钮来处理这些被勾选的行。我单击它,它只会将第一行标识为被勾选。其余的现在显然是空的..?
那么,我如何以编程方式在数据网格视图中设置复选框列的值,然后再次读取它,因为根据我的结果,我显然离题了。
这设置了复选框,我可以看到它们,手动取消它们等等。
foreach (DataGridViewRow row in dgv.Rows)
{
var ch1 = new DataGridViewCheckBoxCell();
ch1 = (DataGridViewCheckBoxCell)row.Cells[0];
if (ch1.Value == null)
ch1.Value = false;
switch (ch1.Value.ToString())
{
case "True":
ch1.Value = false;
break;
case "False":
ch1.Value = true;
break;
}
}
然后检查值的下一个按钮就是查找空值
foreach (DataGridViewRow row in rows)
{
var ch1 = new DataGridViewCheckBoxCell();
ch1 = (DataGridViewCheckBoxCell)row.Cells[0];
if (ch1.Value == null)
ch1.Value = false;
switch (ch1.Value.ToString())
{
case "True":
ch1.Value = true;
break;
case "False":
ch1.Value = false;
break;
}
var val = row.Cells["EbayListingID"].Value.ToString();
if (ch1.Value.ToString() == "true") continue;
var listing = dsEntities.EbayListings.First(x => x.EbayListingID.ToString() == val);
SubmitListingForReview(listing, false);
}