Berikut adalah contoh mengambil value pada DataGridView :
1. Mengambil value DataGridView lalu tampung ke TextBox
Dim i As Integer
With DataGridView1
if e.RowIndex >= 0 Then
i = .CurrentRow.Index
TextBox1.text = .Rows(i).Cells("id").Value.ToString
TextBox2.text = .Rows(i).Cells("firstname").Value.ToString
TextBox3.text = .Rows(i).Cells("lastname").Value.ToString
TextBox4.stext = .Rows(i).Cells("address").Value.ToString
End If
End With
2. Mengisikan data Textbox ke DataGridView
With DataGridView1
Dim rnum As Integer = .Rows.Add()
.Rows.Item(rnum).Cells("ID").Value = txtID.Text
.Rows.Item(rnum).Cells("name").Value = txtName.Text
.Rows.Item(rnum).Cells("price").Value = txtPrice.Text
.Rows.Item(rnum).Cells("qty").Value = txtQty.Text
End With
Bisa juga dengan sintak seperti ini
With DataGridView1
Dim rnum As Integer = .Rows.Add()
.Rows.Item(rnum).Cells(0).Value = txtID.Text
.Rows.Item(rnum).Cells(1).Value = txtName.Text
.Rows.Item(rnum).Cells(2).Value = txtPrice.Text
.Rows.Item(rnum).Cells(3).Value = txtQty.Text
End With