Solved

Removing horizontal scroll bar in listview box

Posted on 2002-05-06
13
2,592 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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
 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

777 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