Results 1 to 1 of 1

Thread: Help with code for using Datagrid in place of ListBox

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    43

    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
    Last edited by Hack; Sep 21st, 2009 at 01:38 PM. Reason: Added Code Tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width