Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have a problem, how can i get value from cell of 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? Can anyone give some example coding? than you~

like image 945
Joseph Kim Avatar asked Nov 01 '13 06:11

Joseph Kim


People also ask

How do I select a specific cell in DataGridView in VB net?

Selecting a single cell You can select cells the same way you select rows – by setting their IsSelected property to true : C# VB.NET.

How do I pass DataGridView selected row value to textbox in another form?

Text = Convert. ToString(frm. DataGridView1[0, row]. Value); Textbox2.

What is DataGridView in C#?

The DataGridView control provides a customizable table for displaying data. The DataGridView class allows customization of cells, rows, columns, and borders through the use of properties such as DefaultCellStyle, ColumnHeadersDefaultCellStyle, CellBorderStyle, and GridColor.


2 Answers

The line would be as shown below:

Dim x As Integer    
x = dgvName.Rows(yourRowIndex).Cells(yourColumnIndex).Value
like image 163
D. Bunnell Avatar answered Sep 28 '22 11:09

D. Bunnell


It is working for me

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

enter image description here

like image 45
Adnan Zaheer Avatar answered Sep 28 '22 11:09

Adnan Zaheer