Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Serbia and Montenegro (Yugoslavia)
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Populate Listbox (VB6)

    I just spent the better half of the day trying to just populate a listbox using an ADO connection to an Access 97 database.

    I figured out that you can't just assign the RS object to the Datasource property of the listbox and expect it to populate automatically. I finally set up a loop using the AddItems Method to insert them one by one. I'm finding that it is inserting them all in one row. I verified that I do have Columns set to 2.

    Here is the code. This is all being done in the load event of the form:


    Dim rs As New ADODB.Recordset

    Dim cn As New ADODB.Connection




    cn.Open "Provider=Microsoft.jet.oledb.3.51;" _
    & "Data Source=CatabaseOncology.mdb"

    rs.Source = "SELECT DISTINCT tblPath.MRNumber, tblPath.Seq, tblPath.Path FROM tblPath"

    Set rs.ActiveConnection = cn

    rs.Open , cn

    With lstRM
    Do While Not rs.EOF

    .AddItem rs(1) & rs(2)


    rs.MoveNext

    Loop
    End With


    'Set lstRM.DataSource = rs

  2. #2
    Star Lounger
    Join Date
    Nov 2001
    Location
    Illinois, USA
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Populate Listbox (VB6)

    Mike,
    Unfortunately, the listbox columns in VB are not like the listbox columns in Access. If you stretch the height of your listbox to accomodate more rows you will see somewhat different results, but not what you want. As you've discovered, the listbox with columns scrolls horizontally, not vertically. If the data in your tables is all the same width you might try setting columns back to 0, and putting tabs between the fields:
    listbox.additem rs(1) & vbTab & rs(2)

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Serbia and Montenegro (Yugoslavia)
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Populate Listbox (VB6)

    Thanks, Dottie. It is all making sense now.

    I switched to the Listview control which seems to be a lot more friendly

Posting Permissions

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