Error adding node - Specified argument was out of the range of valid values. Parameter name: Index was out of range. Must be non-negative and less than the size of the collection.

Last post 01-07-2009 10:20 AM by drewdog. 1 replies.

Sort Posts:

  • Error adding node - Specified argument was out of the range of valid values. Parameter name: Index was out of range. Must be non-negative and less than the size of the collection.

    01-06-2009, 3:34 PM
    • Member
      point Member
    • drewdog
    • Member since 01-06-2009, 3:27 PM
    • Posts 2

     I have a recordset that I loop thru adding nodes to my treeview.

    Well at around record # 123 out of 500 or so, I get this error adding child node :

    "Specified argument was out of the range of valid values.
    Parameter name: Index was out of range.  Must be non-negative and less than the size of the collection."

     The node I'm adding to exists, and I can't see anything wrong w/ the data -  and it always gets hung up on the same record.

    *And the same code has been used 122 times already w/out issue. *

    Any ideas ?  my code:

     'lastDivisionIndex = 1

    'lastOfficeIndex = 1.0

     item = New TreeNode
            item.Text = dr("employee_name") 'value=Borek, Jeffry
            item.NodeData = dr("app_user_id") 'value=118
            tv1.Nodes(lastDivisionIndex).Nodes(lastOfficeIndex).Nodes.Add(item) 'error here, record 123 out of 500 records in recordset
            item = Nothing

  • Re: Error adding node - Specified argument was out of the range of valid values. Parameter name: Index was out of range. Must be non-negative and less than the size of the collection.

    01-07-2009, 10:20 AM
    • Member
      point Member
    • drewdog
    • Member since 01-06-2009, 3:27 PM
    • Posts 2

     Found the problem.

     I was using "item.GetNodeIndex" to get the lastIndex, and its returning a String with a float value - whereas the Index in Nodes collections takes an integer.

    So something like 0.1 will always be 0, and was screwing everything up.

    I'm now keeping tracking of the node Index with an actual Integer, and voila it works -  I guess this is a bug  ?

     Here's working code:

    Dim item As TreeNode = New TreeNode
            item.Text = dr("office_name")
            item.NodeData = dr("office_id")
            tv1.Nodes(lastDivisionIndex).Nodes.Add(item)
            'lastOfficeIndex = item.GetNodeIndex   'should return Integer, bug ?
            lastOfficeIndex += 1    ' keep manual track of Index w/ local Integer variable
            lastOfficeID = dr("office_id")
            item = Nothing

Page 1 of 1 (2 items)
Microsoft Communities