By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,307 Members | 1,585 Online
Bytes IT Community
Submit an Article
Got Smarts?
Share your bits of IT knowledge by writing an article on Bytes.

Adding Items to Listview Manually.

debasisdas
Expert 5K+
P: 8,127
Select Microsoft windows common controls 6.0 (SP6) from components
Add a ListView control to the form.
Add 2 ImageList controls to the form.
Add some bitmaps to both the imagelist.
Set the name of image list to the Normal and small icon Image List from the Image lists tab in property pallet of the Listview control.
Add a combobox .

Add this sample code to the form
=============================
Expand|Select|Wrap|Line Numbers
  1. Private Sub Combo1_Click()
  2. LV1.View = Combo1.ListIndex
  3. End Sub
  4.  
  5. Private Sub Form_Load()
  6. Dim C As ColumnHeader
  7. Dim i As Integer
  8. For i = 1 To 4
  9. Set C = LV1.ColumnHeaders.Add()
  10. C.Text = "Field" & i
  11. C.Width = LV1.Width / 4
  12. Next i
  13.  
  14. Dim li1 As ListItem
  15. Set li1 = LV1.ListItems.Add()
  16. li1.Text = "Item 1"
  17. li1.Icon = 4
  18. li1.SmallIcon = 1
  19. LV1.ListItems(1).ListSubItems.Add , , "Field2"
  20. LV1.ListItems(1).ListSubItems.Add , , "Field3"
  21. LV1.ListItems(1).ListSubItems.Add , , "Field4"
  22.  
  23. Dim li2 As ListItem
  24. Set li2 = LV1.ListItems.Add()
  25. li2.Text = "Item 2"
  26. li2.Icon = 4
  27. li2.SmallIcon = 1
  28. LV1.ListItems(2).ListSubItems.Add , , "Field2"
  29. LV1.ListItems(2).ListSubItems.Add , , "Field3"
  30. LV1.ListItems(2).ListSubItems.Add , , "Field4"
  31.  
  32. Dim li3 As ListItem
  33. Set li3 = LV1.ListItems.Add()
  34. li3.Text = "Item 3"
  35. li3.Icon = 4
  36. li3.SmallIcon = 1
  37. LV1.ListItems(3).ListSubItems.Add , , "Field2"
  38. LV1.ListItems(3).ListSubItems.Add , , "Field3"
  39. LV1.ListItems(3).ListSubItems.Add , , "Field4"
  40.  
  41. With Combo1
  42. .AddItem "Icon View"
  43. .AddItem "Small Icon View"
  44. .AddItem "List View"
  45. .AddItem "Report View"
  46. End With
  47.  
  48. End Sub
  49.  
  50.  
Oct 18 '07 #1
Share this Article
Share on Google+