Link to home
Start Free TrialLog in
Avatar of I_jolly
I_jolly

asked on

ListView control

I am using a ListView Control.  When I add more items than the ListView can display a Horizontal and Vertical scrollbar is displayed which is a bit Naff.  I only really want a Vertical one displayed.  Does anyone know a solution other than FlatScrollBar???
Avatar of caraf_g
caraf_g

Adjust the width of your column headers when the number of list items * the height of the list items exceeds the height of the list view.
Try the following as an example: For more than one column you may want to modify only the last column's width, or all columns.... it's up to you. Don't take the values I entered as Gospel either, I found them by trial and error:

Option Explicit

Private Sub Command1_Click()

Dim intColumnHeaderHeight As Integer
Dim intLVBorderWidth As Integer
Dim intVerticalScrollBarWidth As Integer

intColumnHeaderHeight = 14 * Screen.TwipsPerPixelY
intLVBorderWidth = 6 * Screen.TwipsPerPixelX
intVerticalScrollBarWidth = 16 * Screen.TwipsPerPixelX

With ListView1
    .ListItems.Add , , "test"

    If .ListItems(1).Height * .ListItems.Count > .Height - intColumnHeaderHeight Then
        .ColumnHeaders(1).Width = .Width - intLVBorderWidth - intVerticalScrollBarWidth
    Else
        .ColumnHeaders(1).Width = .Width - intLVBorderWidth
    End If
End With

End Sub

Private Sub Form_Load()

Dim intLVBorderWidth As Integer

intLVBorderWidth = 6 * Screen.TwipsPerPixelX

With ListView1
    .ColumnHeaders.Add , , "hi", .Width - intLVBorderWidth
    .LabelEdit = lvwManual
    .View = lvwReport
End With

End Sub
Avatar of I_jolly

ASKER

Hi caraf_g,
This is a good answer and is very similar to what I am doing now.  I will re-open the question though just to see if there is another, more compact, method of doing this as this was what I was looking for.  If there isn't I will award you the points.  
ASKER CERTIFIED SOLUTION
Avatar of caraf_g
caraf_g

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of I_jolly

ASKER

Thanks for the help.
Sorry you didn't get a better answer. Thanks for the points!