Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ArgumentOutOfRangeException Error

Status
Not open for further replies.

EZEason

Programmer
Dec 11, 2000
213
US
I'm new to .net so go easy on my. I have a treeview that is re-populated when different radio buttons are clicked.
I'm using ADO.net to get the data from SQL. I'm trying to save a string into the Tag of the treeview.node, but keep getting this error when I try to re-populate the Tag.
An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in system.windows.forms.dll

Additional information: Specified argument was out of the range of valid values

Here is the code:
Code:
        Dim l As Integer = A.Tables("Field").Rows.Count - 1
        For l = 0 To A.Tables("Field").Rows.Count - 1
            TreeView1.Nodes.Add(New TreeNode(A.Tables("Field").Rows(l).Item("Field_English")))
            '''Add Child to treeview and Tag
            Dim p As Integer = B.Tables("Area").Rows.Count - 1
            For p = 0 To B.Tables("Area").Rows.Count - 1
                If A.Tables("Field").Rows(l).Item("Field_Code") = B.Tables("Area").Rows(p).Item("Field_Code") Then
                    TreeView1.Nodes(l).Nodes.Add(New TreeNode(B.Tables("Area").Rows(p).Item("Field_Area_Code") & "  " & B.Tables("Area").Rows(p).Item("Field_Area_English")))
     ''Errors here [COLOR=blue] TreeView1.Nodes(l).Nodes(p).Tag = B.Tables("Area").Rows(p).Item("Field_Code") & "-" & B.Tables("Area").Rows(p).Item("Field_Area_Code")[/color]
                End If
            Next
        Next

Do I need to clear the Tag?
What am I missing?

What doesn't kill you makes you stronger.
 
I found my problem. I was over counting the nodes with the Nodes(p). So I added a different count (m) that went in order of the child Node as it was added. See below
Code:
        [COLOR=green]Dim m As Integer[/color]
        Dim l As Integer = A.Tables("Field").Rows.Count - 1
        For l = 0 To A.Tables("Field").Rows.Count - 1
            TreeView1.Nodes.Add(New TreeNode(A.Tables("Field").Rows(l).Item("Field_English")))
            '''Add Child to treeview and Tag
           [COLOR=green] m = 0[/color]
            Dim p As Integer = B.Tables("Area").Rows.Count - 1
            For p = 0 To B.Tables("Area").Rows.Count - 1
                If A.Tables("Field").Rows(l).Item("Field_Code") = B.Tables("Area").Rows(p).Item("Field_Code") Then
                    TreeView1.Nodes(l).Nodes.Add(New TreeNode(B.Tables("Area").Rows(p).Item("Field_Area_Code") & "  " & B.Tables("Area").Rows(p).Item("Field_Area_English")))
                    TreeView1.Nodes(l).Nodes(m).Tag = B.Tables("Area").Rows(p).Item("Field_Code") & "-" & B.Tables("Area").Rows(p).Item("Field_Area_Code")
                   [COLOR=green] m = m + 1[/color]
                End If
            Next
        Next

What doesn't kill you makes you stronger.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top