vb.net 将单元格值从数据网格视图传递到文本框而不单击单元格
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14767413/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Passing cell value from datagridview to textbox without clicking the cell
提问by Cindy Pascual
My program imports excel files and after this, all the data in excel has been shown in
DatagridView. I want a specific cell to pass its value to Textbox.
我的程序导入了 excel 文件,此后,excel 中的所有数据都以 .csv 格式显示
DatagridView。我想要一个特定的单元格将其值传递给Textbox.
I have tried using Me.TextBox3.Text = DataGridView1.Rows(15).Cells(2).Value.ToString()But there's an error which is cannot be converted in string..
row15, column2 has text..
我试过使用 Me.TextBox3.Text = DataGridView1.Rows(15).Cells(2).Value.ToString()但有一个错误,无法在字符串中转换.. row15, column2 has text..
回答by SysDragon
I guess this error (error converting into string) is because the value is Nothing. The indexes begin in 0, so, as Andrey commented, for reaching row 15 and second column you have to do it this way:
我猜这个错误(错误转换为字符串)是因为值是Nothing. 索引从 0 开始,因此,正如 Andrey 评论的那样,要到达第 15 行和第二列,您必须这样做:
Me.TextBox3.Text = DataGridView1.Rows(15).Cells(1).Value.ToString()

