|
-
Mar 31st, 2006, 12:42 PM
#1
Thread Starter
Member
[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.
-
Mar 31st, 2006, 02:00 PM
#2
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:
Dim MyItem As ListItem
Do While Not Rs.EOF
Set MyItem = ListView1.ListItems.Add(, , RecordSetObject.Fields.Item("fieldname1").Value)
MyItem.SubItems(1) = RecordSetObject.Fields.Item("fieldname2").Value)
MyItem.SubItems(2) = RecordSetObject.Fields.Item("fieldname3").Value)
Rs.MoveNext
Loop
-
Mar 31st, 2006, 07:49 PM
#3
Frenzied Member
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:
Sub FillListView(lv As ListView, rs As ADODB.Recordset, Optional ImgNum As Long = 0)
lv.ListItems.Clear
If Not rs.BOF Then
rs.MoveFirst
Dim a As Long
Dim lst As ListItem
While Not rs.EOF
lst.Ghosted = True
Set lst = lv.ListItems.Add(, , rs.Fields(0).Value, , ImgNum)
For a = 1 To lv.ColumnHeaders.Count - 1
lst.SubItems(a) = rs.Fields(a).Value
Next
rs.MoveNext
Wend
End If
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
-
Apr 1st, 2006, 02:24 AM
#4
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|