|
-
Jun 15th, 2003, 04:42 PM
#1
Thread Starter
Lively Member
Adding a node to a treeview on a different form...
Okay, i have 2 forms. Im looking to create a seperate form that a user can enter the name of the node as. I have this
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
user = TextBox1.Text
Dim newnode As TreeNode = New TreeNode(user)
forms.myform1.TreeView1.SelectedNode.Nodes.Add("test")
forms.myform2.Hide()
End Sub
the show/hide form2 works, but i get this for the treeview:
Additional information: Object reference not set to an instance of an object.
-
Jun 16th, 2003, 03:18 AM
#2
Sleep mode
I think it's making that error because you are creating the treeview node on the form1 , though you want it to be created on form2 for example . One solution (I've not tried this) I might think of is to create one or array of treeview nodes on form2 , when you need them , they are there . Just pass the string the user will enter . I dunno if this will work for you but it's worth a try .
-
Jun 16th, 2003, 08:58 AM
#3
Thread Starter
Lively Member
i want the node too be created on form one. form 2 is naming the node
-
Jun 17th, 2003, 01:04 PM
#4
You need to point to your instance of Form1. So that instance has to be accessilbe by Form2 either by having the instance as a global variable or passing the instance to Form2 via the new method.
-
Jun 19th, 2003, 10:49 PM
#5
Thread Starter
Lively Member
Yes, ive tried that, but that means i have to show a new form 1
-
Jun 20th, 2003, 01:58 AM
#6
The easiest and best way is to either have the child form return a treenode to the main form for call a method on the main form that does the actual creating. You could do this via a delegate or just a public method.
-
Jun 20th, 2003, 02:05 PM
#7
Thread Starter
Lively Member
hmmm... could you explain that a little bit? im still a bit new to .net
-
Jun 20th, 2003, 03:57 PM
#8
Here is an example of both ways with explanation in the code notes.
-
Jun 20th, 2003, 04:51 PM
#9
Thread Starter
Lively Member
hmmm... i cant seem to open it in vb, i have unzipped it
-
Jun 20th, 2003, 05:20 PM
#10
Frenzied Member
I think you might need VS.NET 2003, since I think thats what Edneesis is using.
-
Jun 20th, 2003, 05:25 PM
#11
Yes that is what I am using, but if you have VS 2002 then you can convert it back to 2002. Someone has a link to the converter in their signature, Pirate maybe?
Yes its in his signature as 'Utility to Convert Visual Studio.NET 2003 Project Files' or here I'll cut and paste it for ya:
http://www.codeproject.com/useritems/VSConvert.asp
There isn't anything in the project that will be different in 2002.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|