我看过一些类似这个问题的帖子,但我还没有想出我的答案,所以我想我会再次浮动它看看会发生什么......
我正在使用 ExcelDNA 使用 C#.NET 将 API 与 Excel 集成。我有一个 DataGridView,我想检查列表中已经存在的项目。
以下代码在绑定到按钮单击事件时有效,但在方法中调用代码时无效。
private void SelectAllItems()
{
foreach (DataGridViewRow row in itemsBySupplier.Rows)
{
DataGridViewCheckBoxCell check = (DataGridViewCheckBoxCell)row.Cells["selectItem"];
check.Value = check.TrueValue;
}
}
我在其他地方也遇到了同样的问题:
foreach (DataGridViewRow row in itemsBySupplier.Rows)
{
DataGridViewCheckBoxCell check = (DataGridViewCheckBoxCell)row.Cells["selectItem"];
string hid = row.Cells["Hid"].Value.ToString();
if (Ws.ToCreate[_supplier].Count(i => i.Hid == hid) > 0)
{
check.Value = check.TrueValue;
}
}
我已经研究了几个小时,完全是空的。任何帮助将不胜感激。