Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2926
  • Last Modified:

Removing horizontal scroll bar in listview box

Is it possible, if so how?
0
jackjeckyl
Asked:
jackjeckyl
  • 7
  • 4
  • 2
1 Solution
 
jackjeckylAuthor Commented:
No matter what I adjust that damn scroll bar is always there, and doesn't need to be.

Here's how I am populating it......

With ListView1
    .View = lvwReport
    Set colX = ListView1.ColumnHeaders.Add()
    colX.Text = "DDA"
    colX.Width = ListView1.Width / 5
    Set colX = ListView1.ColumnHeaders.Add()
    colX.Text = "Total Deposit"
    colX.Width = ListView1.Width / 5
    Set colX = ListView1.ColumnHeaders.Add()
    colX.Text = "Immediate"
    colX.Width = ListView1.Width / 5
    Set colX = ListView1.ColumnHeaders.Add()
    colX.Text = "One Day"
    colX.Width = ListView1.Width / 5
    Set colX = ListView1.ColumnHeaders.Add()
    colX.Text = "Two Day"
    colX.Width = (ListView1.Width / 5.2)
    'colX.Width = (ListView1.Width / 5)
End With

With rsItems
    intNumDDAs = .RecordCount - 1
    Do Until .EOF
        Set NewLine = ListView1.ListItems.Add(, , rsItems(0).Value)
        For intX = 1 To .Fields.Count - 1
            NewLine.SubItems(intX) = Format$((rsItems(intX).Value / 100), "###,###,###.00")
        Next intX
    intY = intY + 1
    .MoveNext
    Loop
End With
0
 
jackjeckylAuthor Commented:
Also, I do not want operators changing the first column.  They can do that now if they click once on that column.  I don't want to disable the whole listview box, either.  Is that possible?
0
 
jgvCommented:
Strange...

I tried your code with the M$ Common Controls 6.0 and the column headers fit perfectly (no scroll bar). When I switched to 5.0, the column headers were wider than the visible area (scroll bar was added). Seems like this might have been a bug correction or the width calculations were changed in 6.0.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jackjeckylAuthor Commented:
No, your right.  The columns fit perfectly.  Its when data is added is when the problem starts.
0
 
jgvCommented:
Looks like your problem is with adding more listitems than will fit in the visible area which will place a vertical scroll bar in the listview. The V scrollbar will overlap your last column and, in turn, force a horizontal scrollbar. I'll see if i can come with something for this.

To prevent editing of the first column, set the LabelEdit to 0 (Manual).
0
 
raizonCommented:
You can try autosizing the columns.  This sis something that I use to do just that and I don't have the scroll bars.  As long as the content isn't wider than the width of the conrol itself.




Private Const LVM_FIRST As Long = &H1000
Private Const LVM_SETCOLUMNWIDTH As Long = (LVM_FIRST + 30)
Private Const LVSCW_AUTOSIZE As Long = -1
Private Const LVSCW_AUTOSIZE_USEHEADER As Long = -2

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Sub lvAutosizeControl(ByVal lv As ListView)
    Dim col2adjust As Long
    For col2adjust = 1 To lv.ColumnHeaders.Count - 1
        Call SendMessage(lv.hwnd, LVM_SETCOLUMNWIDTH, col2adjust, ByVal LVSCW_AUTOSIZE_USEHEADER)
    Next
End Sub

Private Sub Form_Load()
    Call lvAutosizeControl(Me.ListView1)
End Sub
0
 
jackjeckylAuthor Commented:
Raizon, that works, but because of my different column sizes, it looks like shxt.  I would like it just the way I have it, just no horizontal scrolll bar or just barely size it so that the data cannot force a horizontal scroll bar.
0
 
jackjeckylAuthor Commented:
I believe jgy is correct about once it makes a vertical scroll bar, it forces the horizontal.  
0
 
raizonCommented:
It won't force the horizontal spacebar if its not needed.

I have many applications that use the listview that have a virtical scroll bar but no horizontal scroll bar.

Take a look at the width you have set in each column.

Make sure that the sum of the widths does not exceed the total width for the control.
0
 
jackjeckylAuthor Commented:
Raizon, what I posted above is what I use.  The first part of the code sets the columns, and the last column I have smaller than the others.  I can stop the code there and see no horizontal bar is needed.  After I populate the listview box, the bars show up.  None of the data go anywhere near the edge and I even tried changing the format but still no luck.
0
 
jgvCommented:
Try this out with a new project and see if it is what you need.

Listview visible item count found at:
http://www.mvps.org/vbnet/code/comctl/lvvisibleitemcount.htm

    Private Const LVM_FIRST As Long = &H1000
    Private Const LVM_GETCOUNTPERPAGE As Long = (LVM_FIRST + 40)
   
    Private Declare Function SendMessage Lib "user32" _
       Alias "SendMessageA" _
      (ByVal hwnd As Long, _
       ByVal wMsg As Long, _
       ByVal wParam As Long, _
       lParam As Any) As Long

Private Sub Form_Load()

    Dim lngScrollWidth As Long
   
    With ListView1
       .View = lvwReport
       'Set a minimum column width to start
       .ColumnHeaders.Add , , "DDA", 50
       .ColumnHeaders.Add , , "Total Deposit", 50
       .ColumnHeaders.Add , , "Immediate", 50
       .ColumnHeaders.Add , , "One Day", 50
       .ColumnHeaders.Add , , "Two Day", 50
       
        '----Replace with your code to populate the listview-----
        While .ListItems.Count < 15
            .ListItems.Add , , "Item #" & .ListItems.Count
        Wend
        '--------------------------------------------------------
       
        If .ListItems.Count > ListviewVisibleCount Then
            lngScrollWidth = 250 'approx width of scrollbar...adjust as necessary
        End If
       
        .ColumnHeaders(1).Width = (.Width - lngScrollWidth) / 5
        .ColumnHeaders(2).Width = (.Width - lngScrollWidth) / 5
        .ColumnHeaders(3).Width = (.Width - lngScrollWidth) / 5
        .ColumnHeaders(4).Width = (.Width - lngScrollWidth) / 5
        .ColumnHeaders(5).Width = (.Width - lngScrollWidth) / 5.2
    End With

End Sub

Private Function ListviewVisibleCount() As Long
   ListviewVisibleCount = SendMessage(ListView1.hwnd, LVM_GETCOUNTPERPAGE, 0&, ByVal 0&)
End Function
0
 
jgvCommented:
Oops, change:
While .ListItems.Count < 15
  to
While .ListItems.Count < 100

so that the number of listitems will exceed the height
0
 
jackjeckylAuthor Commented:
Works perfectly.  Thank you many.
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 7
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now