String error from casting

absent

Regular
Joined
Sep 25, 2003
Messages
55
Location
UK
Im trying to add nodes to a treeview based on letters of the alphabet using :

Visual Basic:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim i As Integer
        Dim node_letter As String
        trvClients.Nodes.Clear()

        'Set document type
        trvClients.Nodes.Add("Phonebook")

        'set documents
        trvClients.SelectedNode = trvClients.Nodes.Item(0)

        trvClients.ExpandAll()
        trvClients.ShowLines = True
        trvClients.ShowPlusMinus = True
        For i = 1 To 26
            node_letter = Chr(64 + i)
            trvClients.SelectedNode.Nodes.RemoveAt(node_letter)
        Next

End Sub

when I compile I get the folowing error :

An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll

Additional information: Cast from string "A" to type 'Integer' is not valid.

From what I understand about strings the code is right - But it still won't accept it.

Any ideas? Or could someone please point me in the right direction?

Thanx in advance
 
STUPID ME!!!

grrrrrrrrrrrrrrrrrrrr Found my problem in the code. I was supposed to say

Visual Basic:
For i = 1 To 26
            node_letter = Chr(64 + i)
            trvClients.SelectedNode.Nodes[b].Add[/b](node_letter)
        Next

not
Visual Basic:
For i = 1 To 26
            node_letter = Chr(64 + i)
            trvClients.SelectedNode.Nodes.[b]RemoveAt[/b](node_letter)
        Next

But your sugestion did give me an insight to parts of treeviews in vb.net that I had over looked... Thanx a million
 
Back
Top