Microsoft KB Archive/254798: Difference between revisions

From BetaArchive Wiki
m (Text replacement - "&" to "&")
m (Text replacement - """ to """)
 
Line 58: Line 58:
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.<br />
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.<br />
<br />
<br />
In the example shown in the &quot;Steps to Reproduce Behavior&quot; section you can fix the problem by replacing the code in the Command2_Click event procedure with the following code:
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:
<pre class="codesample">Private Sub Command2_Click()
<pre class="codesample">Private Sub Command2_Click()
     Dim n As Integer
     Dim n As Integer
Line 99: Line 99:
      
      
     For i = 1 To 10
     For i = 1 To 10
         TreeViewCtl1.Nodes.Add , , &quot;n&quot; & i, &quot;Node &quot; & i
         TreeViewCtl1.Nodes.Add , , "n" & i, "Node " & i
         For n = 1 To 5
         For n = 1 To 5
             TreeViewCtl1.Nodes.Add &quot;n&quot; & i, tvwChild, _
             TreeViewCtl1.Nodes.Add "n" & i, tvwChild, _
                       &quot;c&quot; & i & n, &quot;Child Node &quot; & n
                       "c" & i & n, "Child Node " & n
             For sn = 1 To 7
             For sn = 1 To 7
                 TreeViewCtl1.Nodes.Add &quot;c&quot; & i & n, _
                 TreeViewCtl1.Nodes.Add "c" & i & n, _
                       tvwChild, &quot;sn&quot; & i & n & sn, &quot;Sub Node &quot; & n & sn
                       tvwChild, "sn" & i & n & sn, "Sub Node " & n & sn
             Next sn
             Next sn
         Next n
         Next n

Latest revision as of 12:52, 21 July 2020

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:

438 Object doesn't support this property or method.

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

  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
         Next
    End Sub
    
    Private Sub Form_OKClick()
        App.End
    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