Listview control

AlexanderBB

Well-known Member
Joined
Jul 1, 2009
Messages
2,072
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
I have a couple of questions about the Listview control I can't find answers for .

Can you hide or set width for 1st column ? It seems to be a special column, not one added by code.
At the end of text is "..." even though the width is well within the column width. To remove them you have to widen the column far more than is needed. Is this adjustable ?
Can you right align numbers ?

Thanks

PS This is in Report view, can't get any others to work !
 
Last edited:

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
What sort of Listbox is it? if it's a forms Control one, try using an ActiveX. You have more control over the properties.
 
Last edited:
Upvote 0
There is no special first column in a listview. Did you clear the columnheaders before adding your own? I also can't replicate your ... issue. You can right align a column easily - I can't recall offhand if it can be done for specific rows in a column (though I doubt it).
 
Upvote 0
I don't know how to setup an 'ActiveX" listbox, this is the (default?) one in the Toolbox. The overly long rows were caused by some non printable characters in the text
that must be included in field length So that's fixed, but I can't remove column one or clear columnheaders. I can get a sort of right alignment by padding with spaces.

Seeems very hard to get good info on ListBoxes, Google mostly finds data for .Net or something else, showing properties that don't exist here.

Anyone know where I can find out more ? Like why only View lvwReport works, and can you get a image into a field? Thanks...
 
Upvote 0
A listbox is not the same as a Listview. Which one are you using, and how are you populating the control?
 
Upvote 0
Oops, sorry I meant listview!

Code:
Private Sub UserForm_Activate()
    Dim i As Integer, theListView As ListItem
    
    LV2.ColumnHeaders.Clear
    LV2.ColumnHeaders.Add , , "WO", 25
    LV2.ColumnHeaders.Add , , "-3", 25
    LV2.ColumnHeaders.Add , , "-2", 25
    LV2.ColumnHeaders.Add , , "-1", 25
   
    LV2.View = lvwReport
 
    With Worksheets("Sheet2")
        For i = 1 To Val(.Cells(1, "L"))
            Set theListView = UserForm2.LV2.ListItems.Add
                theListView.SubItems(1) = "ddd" '.Cells(i, "A")
                theListView.SubItems(2) = .Cells(i, "B")
                theListView.SubItems(3) = .Cells(i, "C")
                If Len(theListView.SubItems(3)) = 1 Then theListView.SubItems(3) = "  " & theListView.SubItems(3)
                theListView.SubItems(4) = .Cells(i, "D")
        Next
    End With
End Sub

I've now found I am setting column one, the confusion is because it is not accepting any data. In the above column 2 is populated with "ddd", whereas it should be column 1.
Seems there's no SubItems(0) allowed.
 
Upvote 0
You should be adding the first text to the Listitem, not a SubItem - for example:

Code:
Set theListView = UserForm2.LV2.ListItems.Add(Text:="ddd")
 
Upvote 0

Forum statistics

Threads
1,223,879
Messages
6,175,148
Members
452,615
Latest member
bogeys2birdies

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