Solved

Removing horizontal scroll bar in listview box

Posted on 2002-05-06
13
2,506 Views
Last Modified: 2007-12-19
Is it possible, if so how?
0
Comment
Question by:jackjeckyl
  • 7
  • 4
  • 2
13 Comments
 

Author Comment

by:jackjeckyl
ID: 6991609
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
 

Author Comment

by:jackjeckyl
ID: 6991664
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
 
LVL 12

Expert Comment

by:jgv
ID: 6991677
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
 

Author Comment

by:jackjeckyl
ID: 6991702
No, your right.  The columns fit perfectly.  Its when data is added is when the problem starts.
0
 
LVL 12

Expert Comment

by:jgv
ID: 6991743
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
 
LVL 5

Expert Comment

by:raizon
ID: 6991752
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:jackjeckyl
ID: 6991776
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
 

Author Comment

by:jackjeckyl
ID: 6991781
I believe jgy is correct about once it makes a vertical scroll bar, it forces the horizontal.  
0
 
LVL 5

Expert Comment

by:raizon
ID: 6991795
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
 

Author Comment

by:jackjeckyl
ID: 6991801
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
 
LVL 12

Accepted Solution

by:
jgv earned 50 total points
ID: 6991814
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
 
LVL 12

Expert Comment

by:jgv
ID: 6991820
Oops, change:
While .ListItems.Count < 15
  to
While .ListItems.Count < 100

so that the number of listitems will exceed the height
0
 

Author Comment

by:jackjeckyl
ID: 6991848
Works perfectly.  Thank you many.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now