Dynamic Listview

adam2079

Board Regular
Joined
May 15, 2008
Messages
51
Hi everyone,

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
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Make the variable Public?
 
Upvote 0
No problem - it's easy to do when you're close to a project. ;)
 
Upvote 0

Forum statistics

Threads
1,216,116
Messages
6,128,934
Members
449,480
Latest member
yesitisasport

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top