Microsoft KB Archive/201577

= BUG: TreeView Scroll Bar Does Not Disappear When You Set Scroll Property to False at Run Time =

Article ID: 201577

Article Last Modified on 12/17/2004

-

APPLIES TO

 Microsoft Visual Basic 6.0 Enterprise Edition, when used with:  Microsoft Windows 95

 Microsoft Windows 98 Standard Edition

 Microsoft Windows Millennium Edition  Microsoft Visual Basic 6.0 Professional Edition, when used with:  Microsoft Windows 95</li></ul>

 Microsoft Windows 98 Standard Edition</li></ul>

 Microsoft Windows Millennium Edition</li></ul> </li> Microsoft Visual Basic 6.0 Learning Edition, when used with:  Microsoft Windows 95</li></ul>

 Microsoft Windows 98 Standard Edition</li></ul>

 Microsoft Windows Millennium Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q201577

<div class="symptoms_section">

SYMPTOMS
If you set the Scroll property of the TreeView control from Microsoft Windows Common Controls (Mscomctl.ocx) to False at run time, the scroll bar does not disappear as expected.

<div class="resolution_section">

RESOLUTION
To work around this problem, call the ShowScrollBar function instead of using the Scroll property. The following example demonstrates how to use the ShowScrollBar function: <ol> Open a new Standard EXE project in Visual Basic. Form1 is created by default.</li> On the Project menu, click Components, select the Microsoft Windows Common Controls 6.0 check box, and then click OK.</li> Add a TreeView control (TreeView1) and a CheckBox control (Check1) to Form1.</li> <li> Add the following code to the General Declarations section of Form1: Option Explicit

Private Const SB_VERT = 1

Private Declare Function ShowScrollBar Lib "user32" _ (ByVal hWnd As Long, ByVal wBar As Long, ByVal bShow As Long) As Long

Private Sub Check1_Click ' The reference to CBool is not required but is used to enhance clarity. Call ShowScrollBar(TreeView1.hWnd, SB_VERT, CBool(Check1.Value)) End Sub

Private Sub Form_Load Dim i As Integer For i = 1 To 20 TreeView1.Nodes.Add, , , "Item " & i   Next i    Check1.Caption = "Show Scroll Bar" Check1.Value = vbChecked End Sub </li> <li>Run the code, and notice that a vertical scroll bar appears on the TreeView control.</li> <li>Click Show Scroll Bar, and notice that the scroll bar disappears. Click Show Scroll Bar again, and notice that the scroll bar re-appears.</li></ol>

<div class="status_section">

STATUS
Microsoft has confirmed this to be a problem in the TreeView control from Microsoft Windows Common Controls (Mscomctl.ocx) under Windows 95, Windows 98, and Windows Millennium Edition.

NOTE: This problem does not occur under Windows NT 4.0 and Windows 2000.

<div class="moreinformation_section">

Steps to Reproduce Behavior
NOTE: You must perform these steps on a computer that is running Windows 95, Windows 98, or Windows Millennium Edition (Me). <ol> <li>Open a new Standard EXE project in Visual Basic. Form1 is created by default.</li> <li>On the Project menu, click Components. In the Components dialog box, select the Microsoft Windows Common Controls 6.0 check box, and then click OK.</li> <li>Add a TreeView control (TreeView1) and a CommandButton control (Command1) to Form1.</li> <li> Add the following code to the General Declarations section of Form1: Option Explicit

Private Sub Command1_Click TreeView1.Scroll = False End Sub

Private Sub Form_Load Dim i As Integer For i = 1 To 20 TreeView1.Nodes.Add, , , "Item " & i   Next i    Command1.Caption = "Hide Scroll Bar" End Sub </li> <li>Run the code, and notice that a vertical scroll bar appears on the TreeView control.</li> <li>Click Hide Scroll Bar, and notice that the scroll bar is still displayed.</li></ol>

<div class="references_section">