Question Retrieve Rows of DataGridView

Benniit

Member
Joined
Mar 14, 2009
Messages
12
Programming Experience
Beginner
Please am new to VB2008 and can someone show me
how to retrieve all the rows into Text boxes when a user clicks on that particular row?

I want the first column("ID") to be retrieved into txtID.text, column("Name") into txtName.text, column("Address") into txtAddress and so on.



Thank you, Gurus.

Ben
 
Sure, bind the textboxes to the fields of the dataset that contain your table, and when you select a row in the DGV the textboxes with change with them.

So select the textbox -> expand DataBindings -> select the text property -> DataSource window will popup -> expand the table(under <yourForm> instances) -> then select the field the textbox will show, repeat for all textboxes...
 
display cell content

you can get value from cells of datagrid to put in which textbox you want. Here is sample code in my project

Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles DataGridView1.CellContentClick
Try
If Not IsDBNull(DataGridView1.CurrentRow.Cells(0).Value.ToString) Then
tb10.Text = DataGridView1.CurrentRow.Cells(0).Value.ToString
tb11.Text = DataGridView1.CurrentRow.Cells(1).Value.ToString
tb12.Text = "" 'DataGridView1.CurrentRow.Cells(2).Value.ToString
tb13.Text = "" 'DataGridView1.CurrentRow.Cells(3).Value.ToString
tb14.Text = DataGridView1.CurrentRow.Cells(4).Value.ToString
tb15.Text = "" 'DataGridView1.CurrentRow.Cells(5).Value.ToString
tb16.Text = DataGridView1.CurrentRow.Cells(6).Value.ToString
tb17.Text = DataGridView1.CurrentRow.Cells(7).Value.ToString
End If
Catch ex As Exception
Exit Sub
End Try
End Sub
 
That's a lot of hard work.

Follow the tutorial in the DW2 link in my signature, section Creating A Simple Data App.

Drop a grid on the form, then switch the data sources mode to DETAILS and drop the details on the form. Many textboxes etc appear.

Because VS has already bound both the grid and the textboxes through the SAME bindingsource, they update in sync with each other
 
Back
Top