如何在选择更改时获取 DataGridView 中的特定单元格
对于列表框,我有以下代码来提取所选的项目:
private void inventoryList_SelectedIndexChanged(object sender, EventArgs e)
{
String s = inventoryList.SelectedItem.ToString();
s = s.Substring(0, s.IndexOf(':'));
bookDetailTable.Rows.Clear();
...
more code
...
}
我想对 DataGridView 执行类似的操作,即当选择更改时,检索所选行中第一个单元格的内容。 问题是,我不知道如何访问该数据元素。
任何帮助是极大的赞赏。
With a listbox, I have the following code to extract the item selected:
private void inventoryList_SelectedIndexChanged(object sender, EventArgs e)
{
String s = inventoryList.SelectedItem.ToString();
s = s.Substring(0, s.IndexOf(':'));
bookDetailTable.Rows.Clear();
...
more code
...
}
I want to do something similar for a DataGridView, that is, when the selection changes, retrieve the contents of the first cell in the row selected. The problem is, I don't know how to access that data element.
Any help is greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这就是您正在寻找的。 但如果没有,希望它能给你一个开始。
I think that this is what you're looking for. But if not, hopefully it will give you a start.
这是使用列名称解决此问题的另一种方法。
如果您需要传递所选行中的数据,可以通过这种方式将其传递到其他表单。
This is another way of approaching to this question using the column name.
If you need to pass the data from that selected row you can pass it this way to the other form.