BUG: TreeView.Visible = False at Design-Time Causes Problems

Last reviewed: March 29, 1996
Article ID: Q149278
The information in this article applies to:
  • Standard, Professional, and Enterprise Editions of Microsoft Visual Basic, 32-bit only, for Windows, version 4.0

SYMPTOMS

After setting the Visible property of a TreeView control to False at design time, odd behavior can be exhibited at run time. The reproduction sample at the end of this article shows two examples. This behavior can range from the Nodes.Count property returning incorrect values to all or some nodes not being displayed, and even to GPFs in some cases.

WORKAROUND

The work around for this problem is to not set the Visible property to False at design time. If a TreeView control needs to be invisible when a form is shown, the Visible property should be toggled in code before the form with the TreeView is shown. This can easily be done in the Form_Load event of the TreeView laden form with this line of code:

   TreeView1.Visible = False

STATUS

Microsoft has confirmed this to be an issue in the Microsoft products listed at the beginning of this article. Microsoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

Steps to Reproduce

  1. Start Visual Basic 4.0. Form1 is created by default.

  2. Add a single TreeView control and two command buttons to Form1.

  3. Set this property of TreeView1:

       Visible:    False
    
    

  4. Add this code to Form1:

       Private Sub Form_Load()
          Dim nodX As Node  ' Create a tree.
          Set nodX = TreeView1.Nodes.Add(,,"r", "Root")
          Set nodX = TreeView1.Nodes.Add(,,"p", "Parent")
       End Sub
    
       Private Sub Command1_Click()
          TreeView1.Visible = True
          Debug.Print TreeView1.Nodes.Count
       End Sub
    
       Private Sub Command2_Click()
          TreeView1.Nodes.Clear
          Debug.Print TreeView1.Nodes.Count
       End Sub
    
    

  5. Press F5 or select Start from the Run menu to start the application. Press the first command button--although the count property will say two, no nodes will be visible in the control. To demonstrate another oddity, stop and restart and then press Command2. The Clear method should have removed all nodes, but the Count property still returns 2.


KBCategory: kbbuglist kbprg
KBSubcategory: PrgCtrlsCus
Additional reference words: 4.00 vb4win vb432




THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: March 29, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.