I have a TreeView on another Form Is this the correct way to Add a Node
Dim NewNode As TreeNode = New TreeNode("String")
Form1.TreeView1.SelectedNode.Nodes.Add(NewNode)
Printable View
I have a TreeView on another Form Is this the correct way to Add a Node
Dim NewNode As TreeNode = New TreeNode("String")
Form1.TreeView1.SelectedNode.Nodes.Add(NewNode)
You have 2 options :
one like yours
or
Form1.Treeview1.SelectedNode.Nodes.Add("new node")
It return the new created node
--
Richard Clark - rc@c2i.fr
______________________________________________
NOUVEAU : Liste de diffusion sur MS.NET
Inscription en envoyant un mail à :
----------------------------------------------
dotnetfrance-subscribe@yahoogroups.com
----------------------------------------------
http://www.c2i.fr - Le portail francophone
Visual Basic,VB.NET,ASP, ASP.NET
+ de 517 aides disponibles (15/02)
______________________________________________
"Jay King" <pggoldpg@hotmail.com> wrote in message
news:3b4a8527@news.devx.com...
> I have a TreeView on another Form Is this the correct way to Add a Node
>
> Dim NewNode As TreeNode = New TreeNode("String")
> Form1.TreeView1.SelectedNode.Nodes.Add(NewNode)
>
>
Ok now the only problem is its giving me errors saying its exspecting an
object..... myabe this is the tim ewhen I tell you I have this code in a
Bas..?
"c2i - Richard Clark" <rc@c2i.fr> wrote in message
news:3b4aa942@news.devx.com...
> You have 2 options :
> one like yours
> or
> Form1.Treeview1.SelectedNode.Nodes.Add("new node")
> It return the new created node
>
>
> --
> Richard Clark - rc@c2i.fr
> ______________________________________________
> NOUVEAU : Liste de diffusion sur MS.NET
> Inscription en envoyant un mail à :
> ----------------------------------------------
> dotnetfrance-subscribe@yahoogroups.com
> ----------------------------------------------
> http://www.c2i.fr - Le portail francophone
> Visual Basic,VB.NET,ASP, ASP.NET
> + de 517 aides disponibles (15/02)
> ______________________________________________
>
> "Jay King" <pggoldpg@hotmail.com> wrote in message
> news:3b4a8527@news.devx.com...
> > I have a TreeView on another Form Is this the correct way to Add a Node
> >
> > Dim NewNode As TreeNode = New TreeNode("String")
> > Form1.TreeView1.SelectedNode.Nodes.Add(NewNode)
> >
> >
>
>
This is the error
Value null was found where an instance of an object was required.
This is the code of my module.. Just in case it might be of use..ect.
Module INIMod
Public Sub Load_Ini()
Dim MF as CPG_INI_EDIT.INIm_Frm
Dim OFD As New OpenFileDialog()
OFD.Filter = "ini files (*.ini)|*.ini|All files (*.*)|*.*"
OFD.FilterIndex = 2
OFD.ShowDialog
Dim LoadStr as New io.StreamReader(OFD.FileName)
Dim LoadLine as String =""
Dim ArryText as New ArrayList()
Do
LoadLine = LoadStr.Readline()
If LoadLine <> Nothing Then
ArryText.Add(LoadLine)
Else:End If
Loop Until LoadLine Is Nothing
Dim X As Integer
Dim CurrentNode as String
For X = 0 To ArryText.Count
Select Case WhatIs(ArryText(X))
Case = 1
'Add Parent Node
'Dim NewNode As TreeNode = New TreeNode(ArryText(X).ToString)
'MF.TV1.SelectedNode.Nodes.Add(NewNode)
'Form1.Treeview1.SelectedNode.Nodes.Add("new node")
MF.TV1.SelectedNode.Nodes.Add(ArryText(X)) '<- Code fails here
CurrentNode = ArryText(X).ToString
Case = 2
'Add Sub Node To Current Parent Node
Case = 3
'Raise Error (Probably Not Initialization File)
Case = 0
'Error! (Unexplained)
End Select
Next
End Sub
Public Function WhatIs(Str as String) as Integer
On Error Goto 10
If mid(Str,1,1) = "[" then
If mid(Str,Len(Str),1) = "]" Then
Return 1
Exit Function
Else:End If
Else:
Return 2
Exit Function
End If
'If Return Int(3) then Probably not Initialization file
Return 3
Exit Function
'Errors Return as Int(0)
10:Return 0
End Function
End Module
Jay,
Where do you initialize MF? I found this code very difficult to read, so
perhaps I missed it. I believe you will then get an invalid cast error on
the same line because you need ArryText(X).ToString.
--
Kathleen
(MS-MVP)
Reply in the newsgroup so everyone can benefit
--
Change your "Dim MF . . ." line to the following:
Dim MF as CPG_INI_EDIT.INIm_Frm = New CPG_INI_EDIT.INIm_Frm
I agree with Kathleen, that code is a little unpleasant to read. . .
Jacob
"Jay King" <pggoldpg@hotmail.com> wrote in message
news:3b4ac7d9@news.devx.com...
> This is the code of my module.. Just in case it might be of use..ect.
>
>
> Module INIMod
> Public Sub Load_Ini()
> Dim MF as CPG_INI_EDIT.INIm_Frm
> Dim OFD As New OpenFileDialog()
> OFD.Filter = "ini files (*.ini)|*.ini|All files (*.*)|*.*"
> OFD.FilterIndex = 2
> OFD.ShowDialog
> Dim LoadStr as New io.StreamReader(OFD.FileName)
> Dim LoadLine as String =""
> Dim ArryText as New ArrayList()
> Do
> LoadLine = LoadStr.Readline()
> If LoadLine <> Nothing Then
> ArryText.Add(LoadLine)
> Else:End If
> Loop Until LoadLine Is Nothing
> Dim X As Integer
> Dim CurrentNode as String
> For X = 0 To ArryText.Count
> Select Case WhatIs(ArryText(X))
> Case = 1
> 'Add Parent Node
> 'Dim NewNode As TreeNode = New TreeNode(ArryText(X).ToString)
> 'MF.TV1.SelectedNode.Nodes.Add(NewNode)
> 'Form1.Treeview1.SelectedNode.Nodes.Add("new node")
> MF.TV1.SelectedNode.Nodes.Add(ArryText(X)) '<- Code fails here
> CurrentNode = ArryText(X).ToString
> Case = 2
> 'Add Sub Node To Current Parent Node
> Case = 3
> 'Raise Error (Probably Not Initialization File)
> Case = 0
> 'Error! (Unexplained)
> End Select
> Next
> End Sub
> Public Function WhatIs(Str as String) as Integer
> On Error Goto 10
> If mid(Str,1,1) = "[" then
> If mid(Str,Len(Str),1) = "]" Then
> Return 1
> Exit Function
> Else:End If
> Else:
> Return 2
> Exit Function
> End If
> 'If Return Int(3) then Probably not Initialization file
> Return 3
> Exit Function
> 'Errors Return as Int(0)
> 10:Return 0
> End Function
> End Module
>
>
I followed your dierections..
Select Case WhatIs(ArryText(X))
Case = 1
'Add Parent Node
Dim MF as CPG_INI_EDIT.INIm_Frm = New CPG_INI_EDIT.INIm_Frm
MF.TV1.Select
MF.TV1.SelectedNode.Nodes.Add(ArryText(X).ToString) 'Fails here again..
Console.WriteLine(ArryText(X).ToString)
Case = 2
'Add Sub Node To Current Parent Node
Console.WriteLine(ArryText(X).ToString)
Case = 3
'Raise Error (Probably Not Initialization File)
Case = 0
'Error! (Unexplained)
End Select
Inline. . .
"Jay King" <pggoldpg@hotmail.com> wrote in message
news:3b4ba812@news.devx.com...
> I followed your dierections..
>
> Select Case WhatIs(ArryText(X))
> Case = 1
> 'Add Parent Node
> Dim MF as CPG_INI_EDIT.INIm_Frm = New CPG_INI_EDIT.INIm_Frm
> MF.TV1.Select
I don't see why you need the above line. . . .
> MF.TV1.SelectedNode.Nodes.Add(ArryText(X).ToString) 'Fails here again..
Are you attempting to add a Root Node (A node with no parent)?
If so, then you can take out the SelectedNode part of the statement.
If you are attempting to add a child node, then you need to be more explicit
in your definition, as to which node is the parent. If you are going on the
assumption that a node will be selected and you wish to add to that node,
then you need to ensure that SelectedNode contains something.
If (MF.TV1.SelectedNode Is Nothing) Then
'Add The Node
Else
'Error
End If
> Console.WriteLine(ArryText(X).ToString)
> Case = 2
> 'Add Sub Node To Current Parent Node
> Console.WriteLine(ArryText(X).ToString)
> Case = 3
> 'Raise Error (Probably Not Initialization File)
> Case = 0
> 'Error! (Unexplained)
> End Select
>
HTH
Jacob