【发布时间】:2021-11-18 11:19:58
【问题描述】:
我正在尝试从表单 1 datagridview 中的选定行中获取单元格的值。我想将此值存储在一个变量中,以便我可以使用该变量使用适当的 ID 更新我的数据库中的特定条目。
我已经在属性中将 datagridview 设置为 public,但由于某种原因,它仍然无法识别我其他表单上的 datagrid。我的代码在表格 2 上如下所示:
var selectedAppointmentId = appointmentDgv.CurrentRow.Cells[0].Value;
Appointment appointment = new Appointment();
appointment.AppointmentID = int.Parse((string)selectedAppointmentId);
此代码位于编辑按钮中,以便我可以对数据库进行更改。我不断收到错误消息:“当前上下文中不存在名称‘appointmentDgv’”。我对 C# 比较陌生。
【问题讨论】:
-
这能回答你的问题吗? Communicate between two windows forms in C#
标签: c# datagridview