[英]How do I retrieve data from cell of selected row in datagridview?
I have a datagridview
with 7 columns, column 0 and 1 are not visible. 我有一个7列的
datagridview
,列0和1不可见。 Column 0 is the ID column. 列0是ID列。 When I select a
row
I would like to get the value in Column 0
. 当我选择
row
我想获取Column 0
的值。 Once I have the value, I can then delete the row from the data table
. 一旦有了值,就可以从
data table
删除行。 Deleting the row from the DataGridView
is not a problem. 从
DataGridView
删除行不是问题。
This line returns the row index
with no problem; 这行返回
row index
没有问题;
int rowIndex = customer_Ship_ContactsDataGridView.SelectedRows[0].Index;
Then with all my research it would appear that this line would get the data from column 0
of the selected row
. 然后,根据我的所有研究,似乎该行将从所选
row
data from column 0
获取data from column 0
。 But it does not. 但事实并非如此。 I get an error that states "When converting a string to DateTime, Parse the string to take the date before......"
我收到一条错误消息,指出“将字符串转换为DateTime时,分析字符串以获取日期之前的日期……”
int contact_ID = int.Parse(customer_Ship_ContactsDataGridView[0, rowIndex].Value.ToString());
Any help with teaching me how to get the value of a column
toString
from the selected row of a DataGridView
would be greatly appreciated. 教我如何从
DataGridView
的选定行中获取toString
value of a column
的value of a column
任何帮助将不胜感激。
I have found my answer in another post Get value in specific column in DataGridView . 我在另一篇文章“ 获取DataGridView中特定列的值”中找到了答案。 I am not sure why I didn't find this last night except that today I simplified my search and came across this post.
我不确定为什么昨晚没有找到这个,除了今天我简化了搜索并发现了这篇文章。 Sorry for any trouble I may have caused, I really do like using this site for help.
很抱歉给我带来任何麻烦,我真的很喜欢使用本网站来寻求帮助。
DataGridViewRow row = customer_Ship_ContactsDataGridView.CurrentCell.OwningRow;
string contact_ID = row.Cells["Contact_ID"].Value.ToString();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.