Microsoft KB Archive/261940

= BUG: eVB: TreeView: Showing Form on NodeClick Event Displays It Behind Active Form =

Article ID: 261940

Article Last Modified on 10/15/2002

-

APPLIES TO


 * Microsoft eMbedded Visual Basic 3.0

-



This article was previously published under Q261940



SYMPTOMS
If you have a project that contains a TreeView control and you show a form in the NodeClick event of the TreeView control, the form that is shown appears behind the form that contains the TreeView control.



CAUSE
After the new form is loaded, the TreeView control fires its GotFocus event. This causes the form that contains the control to get the focus.



RESOLUTION
To work around this problem, set the Enabled property of the TreeView control to False in the NodeClick event before showing the other Form, and then reset the Enabled property to True in the Form_Activate event. Replace the code in the sample under &quot;Steps to Reproduce Behavior&quot; later in this article with the following: Option Explicit

Private Sub Command1_Click Form2.Show End Sub

Private Sub Form_Activate TreeViewCtl1.Enabled = True End Sub

Private Sub Form_Load TreeViewCtl1.Nodes.Add, , , &quot;Node One&quot; TreeViewCtl1.Nodes.Add, , , &quot;Node Two&quot; End Sub

Private Sub TreeViewCtl1_NodeClick(ByVal Index As Long) TreeViewCtl1.Enabled = False Form2.Show End Sub



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce Behavior
 Open Microsoft eMbedded Visual Basic 3.0. Create a new Windows CE HPC PRO project. Form1 is created by default. On the Project menu, click to select Add Form. Form2 is added by default. On the Project menu, click to select Components, and then click to add the Microsoft CE TreeView Control 3.0. Add a CommandButton and a TreeView control to Form1.</li>  Paste the following code into Form1: Option Explicit

Private Sub Command1_Click Form2.Show End Sub

Private Sub Form_Load TreeViewCtl1.Nodes.Add, , , &quot;Node One&quot; TreeViewCtl1.Nodes.Add, , , &quot;Node Two&quot; End Sub

Private Sub TreeViewCtl1_NodeClick(ByVal Index As Long) Form2.Show End Sub </li> Run the project on the device or in emulation, and click on Command1. Form2 is displayed in front of Form1.</li> Close Form2, click on Node One of the TreeView control on Form1, and note that Form2 is displayed behind Form1.</li></ol>

<div class="references_section">