Results 1 to 4 of 4

Thread: Object reference not set to an instance of an object

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Posts
    20

    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.

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    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:
    1. Dim selectedNode As myTreeView1.SelectedNode
    2. MessageBox.Show(selectedNode.MyNewKey)

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Posts
    20
    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)

  4. #4
    Hyperactive Member
    Join Date
    Mar 2004
    Location
    Prato - Tuscany - Italy
    Posts
    461
    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
  •  



Click Here to Expand Forum to Full Width