如何从`DataGridView`中的单个单元格中捕获数据

时间:2014-11-13 06:17:03

标签: c# datagridview

我正在尝试从ID中的DataGridView字段获取值。我将Column标记的Contact_ID设置为visible = false并且工作正常,我可以从列中获取数据。

今天收到错误消息Unhandled acceptation of type和消息Column named Contact_ID cannot be found

我已将Contact_ID visible = true和列宽= 2,因此您无法真正看到它

以下是我使用的2行代码。正好捕获row索引。

DataGridViewRow row = customer_ContactsDataGridView.CurrentCell.OwningRow;
string contact_ID = row.Cells["Contact_ID"].Value.ToString();

感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

在Alex Bell的帮助下,以下是我最终得到的代码行。

DataGridViewRow row = customer_ContactsDataGridView.CurrentCell.OwningRow;
string contact_ID = row.Cells[0].Value.ToString();

使用cell

中的数字DataGridView位置更容易获取数据
相关问题