Question Answered as of 5 Years Ago by
manoshailu Im trying to display data in a datagrid then once a row is selected show a different column of the database in a text box. I use the unique primary key in the datagridview as not visible so once the row is selected, i can get that integer and populate the textbox by using another database query. Of course if there is a way to show the data in the textbox without needed to query the db again that would be great. Could someone please let me know how to get the selected row? Also the rows in the datagridview is set to select the entire row not just a cell if that makes a difference
Try this one
Private Sub mydatagridview_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles mydatagridview.MouseUp
'we will select first the entire row so that we can simply point the cell value to be displayed in the textboxes
Dim hit As DataGridView.HitTestInfo = Me.mydatagridview.HitTest(e.X, e.Y)
If hit.Type = DataGridViewHitTestType.Cell Then
Me.mydatagridview.ClearSelection()
Me.mydatagridview.Rows(hit.RowIndex).Selected = True
Textbox1.Text = Me.mydatagridview.SelectedCells(0).Value
Textbox2.Text= Me.mydatagridview.SelectedCells(1).Value
'do the rest
End If
End Sub
c0deFr3aK
Junior Poster in Training
71 posts since Mar 2009
Reputation Points: 11
Solved Threads: 10
Skill Endorsements: 0