Results 1 to 3 of 3

Thread: Help populating listview with data from mysql

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Help populating listview with data from mysql

    Hi all. i am using the following code to populate my listbox. I wonder how i can modify it so i populate listview instead. My query for listbox outputing one item but for my listview has to output more then one item. I be happy if some one show me how this can be done.Thanks

    qury for the listview:
    select url,author,image,title from videos2
    2 Code:
    1. Private Sub Form_Load()    
    2.    
    3.    
    4. 'Open connection
    5. Dim CNN As ADODB.Connection
    6. Dim RS As ADODB.Recordset
    7. Set CNN = New ADODB.Connection
    8. CNN.Open "DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=test;USER=root;PASSWORD=;OPTION=3;"
    9. 'get records to recordset
    10. Set RS = CNN.Execute("select url,author,image,title from videos2", , adCmdText)
    11.  
    12. 'go through all the records until you get to
    13. 'the end (rs.EOF = True)
    14. Do Until RS.EOF = True
    15. 'Add the records to your listbox
    16. 'ShowScrollBar List2.hwnd, SB_HORIZONTAL, True
    17. List2.AddItem RS!URL
    18. 'start from the first record and then go through them all
    19. 'using .MoveNext
    20. RS.MoveNext
    21. 'get all records (loop)
    22. Loop
    23.  
    24. RS.Close
    25. Set RS = Nothing
    26. CNN.Close
    27. Set CNN = Nothing
    28.  
    29.  
    30.  'horizantal scroll bar
    31.       'List1.AddItem "set the right margin to 3 times the width of the control"
    32.    
    33.     SendMessage List2.hwnd, LB_SETHORIZONTALEXTENT, ScaleX(List2.Width * 3, Me.ScaleMode, vbPixels), 0
    34.     ShowScrollBar List2.hwnd, SB_HORIZONTAL, 1
    35.    
    36. End Sub

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Help populating listview with data from mysql

    Add Column Headers to the ListView and set its View property to Report.

    Code:
    Dim oItem as ListItem
    
    Do Until RS.EOF = True
       Set oItem = Listview1.ListItems.Add(,,rs.fields("url").Value)
       oItem.ListSubItems.Add ,,rs.Fields("author").Value
       oItem.ListSubItems.Add ,,rs.Fields("image").Value
       oItem.ListSubItems.Add ,,rs.Fields("title").Value
       RS.MoveNext
    Loop

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: Help populating listview with data from mysql

    thanks brucevde it worked !! could you tell me how to refrence for example the selected first coloum item and place it inside textbox?

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