How to Populate ListView With Data Instead of ListBox

JarekM

Board Regular
Joined
Nov 13, 2018
Messages
86
Hi, the code below is working, but there is a small problem with it. I have the data populate a ListBox, but I want the data to populate a ListView. Can someone help with this?
I tried to change this code to ListView, but it would not work. So I need someones help with this VBA.

Code:
Private Sub CommandButton1_Click()
Call Display
End Sub


Code:
Private Sub UserForm_Initialize()

  rTABLE6 = "Table6"
 
  TblDB = Range(rTABLE6).Value
  ColNR = UBound(TblDB, 2)
 
  Set d = CreateObject("scripting.dictionary")
    For i = LBound(TblDB) To UBound(TblDB)
      d(TblDB(i, 4)) = ""
    Next i
 
  Me.ChoiceListBox1.List = d.keys
  Set d = CreateObject("scripting.dictionary")
    For i = LBound(TblDB) To UBound(TblDB)
      d(TblDB(i, 6)) = ""
    Next i
 
  Me.ChoiceListBox2.List = d.keys
  Set d = CreateObject("scripting.dictionary")
  d.comparemode = vbTextCompare
    For i = LBound(TblDB) To UBound(TblDB)
      d(TblDB(i, 7)) = ""
    Next i
 
  Me.ChoiceListBox3.List = d.keys
  Me.ListBox1.ColumnCount = ColNR
 
  Call Display
End Sub




Code:
Sub Display()
  Dim Liste(), ok(1 To 3)
 
  n = 0
  For i = LBound(TblDB) To UBound(TblDB)
        For o = 1 To 3: ok(o) = False: Next o
        p = 0
        For Each c In Array(4, 6, 7)
            p = p + 1
            s = 0
           
                For j = 0 To Me("ChoiceListBox" & p).ListCount - 1
                  If Me("ChoiceListBox" & p).Selected(j) Then s = s + 1
                Next j
               
            If s = 0 Then
              ok(p) = True
            Else
           
                For j = 0 To Me("ChoiceListBox" & p).ListCount - 1
                   If Me("ChoiceListBox" & p).Selected(j) Then
                     If TblDB(i, c) = Me("ChoiceListBox" & p).List(j) Then ok(p) = True
                   End If
                Next j
               
             End If
            
        Next c
       
        If ok(1) And ok(2) And ok(3) Then
            n = n + 1
            ReDim Preserve Liste(1 To ColNR, 1 To n)
                For k = 1 To ColNR
                   Liste(k, n) = TblDB(i, k)
                Next k
        End If
  Next i
 
  If n > 0 Then Me.ListBox1.Column = Liste Else Me.ListBox1.Clear
End Sub

Sorry again, I am a beginner to ListView, and I like it a lot, so it would be very appreciative if someone could help me.
Thank you.
 
As My Aswer Is This has already said, please explain in words what you would like to do.
 
Upvote 0

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hi, so I need the Userform to filter out the multi criteria, just like in the picture above. I want Column4 to populate ListView1 from spreadsheet, Column6 to populate ListView2 and column6 populate ListView3. When I check on the criteriainListView1, or 2 or 3, and then press "filter," I want the filtered data to populate ListView4, so the results will show, like on the picture.

If there are any other details you want just ask.



tinypic.com
[/URL][/IMG]



Thank you very much
 
Upvote 0
Thanks for that image.

That's interesting.

I may be able to help but since I have a limited knowledge of Listview I will take this on as a challenge.
But others here may be able to put together a faster answer. I like challenge.

So from this image it appears as if you have already accomplished this task.

So what do you need help on.
 
Last edited:
Upvote 0
Hi, thanks for the quick response, the picture is ListBoxes, I want it to be ListView

Thank you.
 
Upvote 0
When I look at this I see checkbox's

A Listview has checkboxes But a Listbox does not have checkboxes.

So it looks like to me your showing what you want and not what you now have.
 
Upvote 0
Hi,

The picture shows ListBoxes controls and not ListView controls.
ListBoxes also have check boxes, if you go to the properties window in ListBoxes and go down to ListStyle and then in ListStyle you change to 1-fmListStyleOption, you will get checkboxes in ListBox.



Thank you.
 
Upvote 0
OK: My mistake. Thanks.
Since I'm fairly new to Listview. Helping you with this question will be hard for me to do. But I will continue to monitor this thread to see what I can Learn.

Hi,

The picture shows ListBoxes controls and not ListView controls.
ListBoxes also have check boxes, if you go to the properties window in ListBoxes and go down to ListStyle and then in ListStyle you change to 1-fmListStyleOption, you will get checkboxes in ListBox.



Thank you.
 
Upvote 0
I maybe could help.

But like I said in previous post.
We need to know what you trying to do in words.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,220
Messages
6,123,698
Members
449,117
Latest member
Aaagu

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