Help with code for using Datagrid in place of ListBox
I have a form with 10 Textboxes and a ListBox with Acess Database. Opening the form will populate the ListBox and the text fields with the same record. Using VB6 No problem with ListBox code like
Code:
Private Sub OpenRs()
With objRs
.Source = "select * from Employee order by LastName"
.Open
Set DataEmployee.DataSource = objRs
End With
objRs.MoveFirst
showCurrentRec
Exit Sub
Private Sub showCurrentRec()
Dim I As Integer
With objRs
For I = 1 To .Fields.Count - 1
txtEmployee(I - 1).Text = .Fields(I) & ""
Next I
End With
End Sub
Click on item in ListBox wiil fill textfields with data for the selected item. Code like.
Code:
Private Sub lstSelCust_Click()
objRS.MoveFirst
objRS.Move (lstSelcust.ListIndex)
showCurrentRec
Exit Sub
Code work perfectly with the listbox.
How do I adapt the code when I rather use a DataGrid in place of the ListBox to get the same results. Need to change the code for Private Sub lstSelCust_Click(). Tried every thing but nothing works. Want to use the data in the DataGrid field "EmployeeID" to populate the textfields. In other words objRS.move to the record where the Employee ID in the DataGrid match.
Any sample code will be appreciated