Hi everyone,
I've set up a dynamic listview on User Form 1 with the following code:
I also have a Command Button, when I click on it User Form 2 opens.
What I'm then trying to do is populate a label with data from the listview in form 1.
If I was to set up a listview at Design time I would be able to use:
How do I overcome this with a Dynamic Listview?
Thanks
I've set up a dynamic listview on User Form 1 with the following code:
Code:
Option Explicit
Private WithEvents lvwUpdate As MSComctlLib.ListView
Private WithEvents ils1 As MSComctlLib.ImageList
Private Sub UserForm_Initialize()
Set lvwUpdate = Me.Controls.Add("MSComctlLib.ListViewCtrl.2", "ListView1")
Set ils1 = Controls.Add("MSComctllib.ImageListCtrl.2", "ImageList1")
With ils1
.ListImages.Add Index:=1, Picture:=img1.Picture
.ListImages.Add Index:=2, Picture:=img2.Picture
.ListImages.Add Index:=3, Picture:=img3.Picture
.ListImages.Add Index:=4, Picture:=img4.Picture
.ListImages.Add Index:=5, Picture:=img5.Picture
.ListImages.Add Index:=6, Picture:=img6.Picture
.ListImages.Add Index:=7, Picture:=img7.Picture
.ListImages.Add Index:=8, Picture:=img8.Picture
End With
With lvwUpdate
.Appearance = ccFlat
.BorderStyle = ccNone
.Left = 0
.Top = 0
.Height = 100
.Width = 100
.HideColumnHeaders = True
.View = lvwReport
.Gridlines = False
.FullRowSelect = True
.CheckBoxes = False
.LabelEdit = lvwManual
.ColumnHeaderIcons = ils1
.SmallIcons = ils1
.Icons = ils1
.ColumnHeaders.Add , , "Column 1", 0, lvwColumnLeft
.ColumnHeaders.Add , , "Column 2", 25, lvwColumnLeft
.ColumnHeaders.Add , , "Column 3", 25, lvwColumnLeft
.ColumnHeaders.Add , , "Column 4", 25, lvwColumnLeft
.ColumnHeaders.Add , , "Column 5", 25, lvwColumnLeft
End With
End Sub
Private Sub UserForm_Activate()
Dim i As Integer
For i = 1 To 10
lvwUpdate.ListItems.Add , "key" & i, "" ', , 1
lvwUpdate.ListItems(i).SubItems(1) = "Column 1"
lvwUpdate.ListItems(i).SubItems(2) = "Column 2"
lvwUpdate.ListItems(i).SubItems(3) = "Column 3"
lvwUpdate.ListItems(i).SubItems(4) = "Column 4"
Next i
End Sub
I also have a Command Button, when I click on it User Form 2 opens.
What I'm then trying to do is populate a label with data from the listview in form 1.
If I was to set up a listview at Design time I would be able to use:
Code:
Label1 = UserForm1.lvwUpdate.ListItems(UserForm1.lvwUpdate.SelectedItem.Index).ListSubItems(1)
How do I overcome this with a Dynamic Listview?
Thanks