Results 1 to 4 of 4

Thread: [RESOLVED] Populating listview through a recordset

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    57

    Resolved [RESOLVED] Populating listview through a recordset

    Hai, how to populate a listview from a recordset. I want to display records in a datacontrol. I know how to do it using datagrid. I wanted to try new control so i tried listview with set listview.datasource = rs but its not working.
    How can i do it. Please help me out.

    Thank you.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Populating listview through a recordset

    This is a loose example. I don't know how many fields are in your recordset that you want in your Listview, so modify accordingly, and change the field names appropriately
    VB Code:
    1. Dim MyItem As ListItem
    2. Do While Not Rs.EOF
    3.  Set MyItem = ListView1.ListItems.Add(, , RecordSetObject.Fields.Item("fieldname1").Value)
    4.     MyItem.SubItems(1) = RecordSetObject.Fields.Item("fieldname2").Value)
    5.     MyItem.SubItems(2) = RecordSetObject.Fields.Item("fieldname3").Value)
    6.     Rs.MoveNext
    7. Loop

  3. #3
    Frenzied Member d3gerald's Avatar
    Join Date
    Jan 2006
    Posts
    1,348

    Re: Populating listview through a recordset

    this one populates the listview with data from the recordset according to the number of columns that the listview have

    VB Code:
    1. Sub FillListView(lv As ListView, rs As ADODB.Recordset, Optional ImgNum As Long = 0)
    2.     lv.ListItems.Clear
    3.     If Not rs.BOF Then
    4.         rs.MoveFirst
    5.         Dim a As Long
    6.         Dim lst As ListItem
    7.         While Not rs.EOF
    8.             lst.Ghosted = True
    9.             Set lst = lv.ListItems.Add(, , rs.Fields(0).Value, , ImgNum)
    10.             For a = 1 To lv.ColumnHeaders.Count - 1
    11.                 lst.SubItems(a) = rs.Fields(a).Value
    12.             Next
    13.             rs.MoveNext
    14.         Wend
    15.     End If
    16. End Sub
    On error goto Trap

    Trap:
    in case of emergency, drop the case...

    ****************************************
    If this post has been resolved. Please mark it as "Resolved" by going through the "Thread Tools" above and clicking on the "Mark Thread Resolved " option.
    if a post is helpful to you, Please Rate it by clicking on the Rate link right below the avatar

  4. #4

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    57

    Smile Re: Populating listview through a recordset

    Hai everyone, Thank you very much. Its working fine.

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