BUG: TreeView ToolTips Flash When Displayed From Modal Form

ID: Q189608


The information in this article applies to:


SYMPTOMS

When the Microsoft TreeView control has been added to a Visual Basic form, and the user hovers the mouse cursor over a node whose text is longer than the control's width, a ToolTip should appear with that text. However, if the form is being displayed modally, the ToolTips will "flash" on and off repeatedly. This behavior occurs only in the compiled version of the application and not in the Visual Basic design environment (IDE.)

This problem occurs under both Windows 95/98 and NT4 using Visual Basic 6.0, but is limited to the Windows 95/98 platform for Visual Basic 5.0.


RESOLUTION

Whenever possible, limit the use of the TreeView control to non-modal forms. If you need to use the TreeView control in a modal dialog, you can simulate modal behavior using a method such as the one documented below.

NOTE: The following method uses a Do-While loop with a single DoEvents statement to force the program to continually poll and process messages from the message queue while it waits for the dialog to be hidden. While this technique will work in most cases, it is highly inefficient and has been known to cause some problems with control event notification.

NOTE: Microsoft provides this workaround for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose.

To simulate invoking a Visual Basic Form modally, use the following call in place of the normal Show method:


   ShowModalForm Form2 

The code for ShowModalForm is shown below, and can be placed in a Form or standard code module:

   Public Sub ShowModalForm(frmTarget As Form)
      Dim ofrm As Object

      ' Disable all the forms
      For Each ofrm In Forms
        ofrm.Enabled = False
      Next ofrm

      ' Now show the target form non-modal
      frmTarget.Show

      ' If the frmTarget was disabled by the loop above
      ' make sure it is now enabled
      frmTarget.Enabled = True

      ' Sit in a loop until the target form is dismissed
      Do While frmTarget.Visible = True
         DoEvents
      Loop

      ' We have left the loop, so the dialog has been dismissed
      ' Now Enable the forms, and exit the procedure
      For Each ofrm In Forms
         If ofrm.Name = frmTarget.Name Then
            Unload ofrm
         Else
            ofrm.Enabled = True
         End If
      Next ofrm
   End Sub 


STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.


MORE INFORMATION

Steps to Reproduce Behavior

  1. Create a new Standard EXE project. Form1 is created by default.


  2. From the Project menu, click Components, and check "Microsoft Windows Common Controls."


  3. Add a CommandButton to Form1.


  4. Paste the following code into Form1's code window:
    
          Private Sub Command1_Click()
             Form2.Show vbModal
          End Sub
     


  5. From the Project menu, click Add Form and add a new form, Form2, to the project.


  6. Place a TreeView control on Form2. Size it to be about 1/2 inch wide.


  7. Paste the following code into Form2's code window:
    
          Private Sub Form_Load()
             With TreeView1
                .Nodes.Add Key:="TEST1", _
                   Text:="Test1 : Does Long Node Text Name Flash?"
                .Nodes.Add Key:="TEST2", _
                   Text:="Test2 : Does Long Node Text Name Flash?"
                .Nodes.Add Key:="TEST3", _
                   Text:="Test3 : Does Long Node Text Name Flash?"
             End With
          End Sub
     


  8. Choose Make exe from the File menu to compile the project to an EXE.


  9. Run the compiled program and click on Command1. Note that as you hover the mouse over the nodes of the TreeView, the ToolTip that appears will flash.



REFERENCES

For additional information, please see the following article in the Microsoft Knowledge Base:

Q173943 : BUG: TreeView ToolTips Do Not Appear on Windows NT

Additional query words: kbDSupport kbDSD kbVBp kbCtrl kbVBp500bug kbWinOS98 kbVBp600 kbWinOS95


Keywords          : 
Version           : 
Platform          : WINDOWS 
Issue type        : kbbug 

Last Reviewed: June 16, 1999