|
-
Apr 1st, 2004, 07:34 AM
#1
Thread Starter
Junior Member
Object reference not set to an instance of an object
I am creating a class which Inherits the TreeNode class and I am creating my own key property within the class.
I can loop round the collection and display MyNewKey for each entry in the collection as below
oSearch = My TreeNode Collection
oChild = Is My Class Containing the Ney TreeNode Key
For Each oChild In oSearch
msgbox oChild.MyNewKey
Next
The problem I am having is I wish to just get data from MyNewKey with the Node which has been selected and not have it in a loop
I have tried several ways to do this and keep getting the error message Object reference not set to an instance of an object.
I reliase that my problem is my new class has to be linked to the treeview control.
Does anybody have any ideas.
Thanks
Daniel
Last edited by DanielBarnes1; Apr 1st, 2004 at 07:42 AM.
-
Apr 1st, 2004, 08:30 AM
#2
I wonder how many charact
Well you definitely started out correct by Inheriting TreeNode class, and adding your property.
I guess what I don't properly understand is how you are adding them to a treenode control.
Anyway, because treenode control has a selectednode property, if implemented properly you should be able to grab the selectednode, and use your custom key property.
VB Code:
Dim selectedNode As myTreeView1.SelectedNode
MessageBox.Show(selectedNode.MyNewKey)
-
Apr 1st, 2004, 09:05 AM
#3
Thread Starter
Junior Member
This does not seem to work. It doesn't let me declare SelectedNode as the TreeView control.
I am using the following line to declasre SelectedNode
Code:
Dim SelectedNodeAs treeview1.selectedmode
Do you have any other Ideas Or am I just be stuppid
Also I use the following line of code to add the Node and my Key
Code:
oNode.Nodes.Add(New MyTreeNodeClass(sString, sKey)
-
Apr 1st, 2004, 10:16 AM
#4
Hyperactive Member
I have never used the controls you are discussing about, anyway the kind of error you obtained, in many cases is due to the fact that in a declaration you didn't put "new", that means the object is not created. For example
Dim oForm as FrmIDesignedYesterday
will give you the same problem. If you write:
Dim oForm as NEW FrmIDesignedYesterday
It works!
Obviously everyword I have written will result absolutely out of the problem, I think.
Good job
Live long and prosper (Mr. Spock)
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
|