c# - 在 DataGridView C# 中获取特定的选中单元格
问题描述
我有一个带有复选框列的 datagridview。我编写了一些代码,以便在检查一行时会发生一个过程。但是,代码运行良好,但不读取已检查的特定行,而是沿每一行向下运行。
如何检查是否已检查特定行?
这是我的代码:
void ViewSignature(DataGridView AllContacts)
{
foreach (DataGridViewRow row1 in AllContacts.Rows)
{
try
{
if (Convert.ToBoolean(row1.Cells[18].Value = true))
{
Process.Start(Properties.Settings.Default.ReferencePoint + @"/Contacts/Contact_" + row1.Cells[0].Value.ToString() + @"/Signature.jpg");
}
return;
}
catch
{
//Error message if the system cannot remove the contact from the database.
MessageBox.Show("Sorry, something went wrong. Please try again later.\n\nERROR CODE: BINSPIRE1009", "BLUEBERRY INSPIRE 2022", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
请注意,这只是虚假内容,电话号码和电子邮件地址是假的。
单击上面的按钮后,该过程应该运行。
解决方案
我设法通过使用语句解决了这个问题datagridview.endedit()
。
我在另一个论坛上读到,当使用按钮时,datagridview 的编辑状态被终止,因为焦点切换到按钮。但是,在使用工具条和菜单条中的项目时情况并非如此,因此需要上述语句来终止 datagridview 的编辑过程,以便工具条可以成功执行其过程。
推荐阅读
- python - 如何在python中使用argv函数进行简单的添加
- html - positiong carousal @ 导航栏后面的顶部
- angular - 带有 3 个 or 子句和空对象的 NgIF
- javascript - 将本地插件添加到 CKEditor
- r - 替换中位数时不正确的 Rscript 工作
- java - 如何使用 JCache 注释 @CacheRemoveAll 清除多个缓存?
- odoo - 当 odoo11 中的 pos 中的重印收据按钮为真时,账单按钮不起作用
- java - 如何在多个并行线程中运行单个 testng 测试用例
- c++ - printf() 中 %f 和 %F 的区别?
- c - makefile 中未定义对“func”错误的引用