Microsoft KB Archive/254798

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 12:52, 21 July 2020 by X010 (talk | contribs) (Text replacement - """ to """)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Article ID: 254798

Article Last Modified on 10/15/2002


  • Microsoft eMbedded Visual Basic 3.0

This article was previously published under Q254798


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:

438 Object doesn't support this property or method.


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
End Sub


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

  1. Start a new Windows CE project in eMbedded Visual Basic.
  2. On the Project menu, select Components, and then check Microsoft CE TreeView Control 3.0.
  3. Put a TreeView control and two Command buttons on the form (Command1 and Command2). Set the LineStyle property of the TreeView control to 1.
  4. 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
    End Sub
    Private Sub Form_OKClick()
    End Sub
  5. Press the F5 key to run the project.
  6. Click Command1, and note that the Treeview is populated.
  7. Double-click a node to expand it.
  8. 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