[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.
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
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
Re: Populating listview through a recordset
Hai everyone, Thank you very much. Its working fine.