简体   繁体   English

如何从 VB.Net 中的 DataGridView 获取单元格值?

[英]How to get cell value from DataGridView in VB.Net?

I have a problem, how can i get value from cell of datagridview我有一个问题,如何从 datagridview 的单元格中获取值

----------------------------------
id     | p/w       | post       |
----------------------------------
1      |   1234    | A          |
----------------------------------
2      | 4567      | S          |
----------------------------------
3      | 6789      | A          |
----------------------------------

I want to get 3 into the textbox,how to do that?我想在文本框中输入 3,该怎么做? Can anyone give some example coding?谁能给出一些示例编码? than you~比你~

The line would be as shown below:该行如下所示:

Dim x As Integer    
x = dgvName.Rows(yourRowIndex).Cells(yourColumnIndex).Value

It is working for me它对我有用

MsgBox(DataGridView1.CurrentRow.Cells(0).Value.ToString)

在此处输入图片说明

To get the value of cell, use the following syntax,要获取单元格的值,请使用以下语法,

datagridviewName(columnFirst, rowSecond).value

But the intellisense and MSDN documentation is wrongly saying rowFirst, colSecond approach...但是智能感知和 MSDN 文档错误地说rowFirst, colSecond方法......

如果你想知道 de selected 行的数据,你可以试试这个片段代码:

DataGridView1.SelectedRows.Item(0).Cells(1).Value

This helped me get close to what I needed and I will throw this out there for anyone else who needs it.这帮助我接近我需要的东西,我会把它扔给任何需要它的人。

If you are looking for the value in the first cell in the selected column, you can try this.如果您要查找所选列的第一个单元格中的值,您可以试试这个。 (I chose the first column, since you are asking for it to return "3", but you can change the number after Cells to get whichever column you need. Remember it is zero-based.) (我选择了第一列,因为您要求它返回“3”,但是您可以更改 Cells 之后的数字以获得您需要的任何列。记住它是从零开始的。)

This will copy the result to the clipboard: Clipboard.SetDataObject(Me.DataGridView1.CurrentRow.Cells(0).Value)这会将结果复制到剪贴板: Clipboard.SetDataObject(Me.DataGridView1.CurrentRow.Cells(0).Value)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM