VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



How to add records to listview control

by king (24 Submissions)
Category: Custom Controls/Forms/Menus
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Mon 26th January 2004
Date Added: Mon 8th February 2021
Rating: (1 Votes)

How to add records to listview control

API Declarations


just follow these easy steps ..

Rate How to add records to listview control



to add records in the listview control the syntax is::

note that the listview control has text and subitems . the first column is text and then other columns are for subitems . You can add as many subitems you want.

If you want to add records on the click event perform this action

dim items as listitem
Set items = lst.ListItems.Add(,,"item1")
items.SubItems(1) = "item2"

okk if you want to add records from the database the syntax is the same write this code on the click event.

first make the procedure listv
Dim items As ListItem
On Error Resume Next
sql = "Select * from employees"
rs.Open sql, conn, adOpenForwardOnly, adLockOptimistic
While Not rs.EOF
Set items = lst.ListItems.Add(, , rs.Fields(0))
items.SubItems(1) = rs.Fields(1)
items.SubItems(2) = rs.Fields(2)
items.SubItems(3) = rs.Fields(3)
items.SubItems(4) = rs.Fields(4)
items.SubItems(5) = rs.Fields(5)

rs.MoveNext
Wend
  rs.Close

End Sub

note you can add all the fields in the database i have just shown the example of adding 5 records in the database.
rs.fields(0)
rs is the name of the recordset
fields 0 means the first field of the database


if you want to ask me any questions regarding to list view control you can email me on [email protected]

Download this snippet    Add to My Saved Code

How to add records to listview control Comments

No comments have been posted about How to add records to listview control. Why not be the first to post a comment about How to add records to listview control.

Post your comment

Subject:
Message:
0/1000 characters