Article ID: 254798
Article Last Modified on 10/15/2002
APPLIES TO
- Microsoft eMbedded Visual Basic 3.0
This article was previously published under Q254798
SYMPTOMS
When you use the For Each statement to go through each node in the Nodes collection of the TreeView control, you encounter the following run-time error message:
RESOLUTION
You can work around the problem by using the Nodes.Count property to obtain the number of Nodes in the Treeview, and then loop through the nodes in the collection by using the index of the node.
In the example shown in the "Steps to Reproduce Behavior" section you can fix the problem by replacing the code in the Command2_Click event procedure with the following code:
Private Sub Command2_Click() Dim n As Integer On Error Resume Next For n = 1 To TreeViewCtl1.Nodes.Count If Err.Number <> 0 Then MsgBox Err.Number & vbCr & Err.Description End If If TreeViewCtl1.Nodes(n).Expanded Then TreeViewCtl1.Nodes(n).Expanded = False End If Next End Sub
STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.
MORE INFORMATION
Steps to Reproduce Behavior
- Start a new Windows CE project in eMbedded Visual Basic.
- On the Project menu, select Components, and then check Microsoft CE TreeView Control 3.0.
- Put a TreeView control and two Command buttons on the form (Command1 and Command2). Set the LineStyle property of the TreeView control to 1.
Paste the following code into the code window of the form:
Option Explicit Private Sub Command1_Click() Dim i As Integer, n As Integer, sn As Integer For i = 1 To 10 TreeViewCtl1.Nodes.Add , , "n" & i, "Node " & i For n = 1 To 5 TreeViewCtl1.Nodes.Add "n" & i, tvwChild, _ "c" & i & n, "Child Node " & n For sn = 1 To 7 TreeViewCtl1.Nodes.Add "c" & i & n, _ tvwChild, "sn" & i & n & sn, "Sub Node " & n & sn Next sn Next n Next i TreeViewCtl1.Style = tvwTreelinesPlusMinusText End Sub Private Sub Command2_Click() Dim n As Node On Error Resume Next For Each n In TreeViewCtl1.Nodes If Err.Number <> 0 Then MsgBox Err.Number & vbCr & Err.Description End If If n.Expanded Then n.Expanded = False End If Next End Sub Private Sub Form_OKClick() App.End End Sub
- Press the F5 key to run the project.
- Click Command1, and note that the Treeview is populated.
- Double-click a node to expand it.
- Click Command2 to try to collapse expanded nodes, and note that the run-time error message 438 occurs.
Additional query words: 438
Keywords: kbbug kbtoolkit kbpending KB254798