Results 1 to 5 of 5

Thread: Access object in treeview tag

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2012
    Posts
    40

    Access object in treeview tag

    Good morning Forum,
    I have come across a problem trying to access an object I assigned to one of my nodes in a treeview. I used the following code to assign the object.
    Code:
    NodeInfo.Type = "Item"
    NodeInfo.Index = 100 
    BidItemNode.Tag = NodeInfo
    NodeInfo is a Structure

    Code:
    Structure tvTag
            Public Type As String
            Public Index As Integer
        End Structure
    How do I access the data now stored in the tag property of the treeview? I have tried the following with no luck

    Code:
    dim rNodeInfo as tvTag = NodeInfo.Tag

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: Access object in treeview tag

    what does that mean? Did you accidentally fire off a nuclear warhead or something? Did you get something you didn't expect or did you not get something that you should have?

    Since it's a structure type, it's also being treated as a value type... so depending on how you loaded it in the first place could also have some impact. Also... don't forget that the .Tag member is a nOBJECT type... so anything you put in there needs to be converted back to the correct type when extracting it. Since you didn't get a compile warning or error on that last line of code... that tells me you have Option Strict and possibly Option Explicit turned off.


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2012
    Posts
    40

    Re: Access object in treeview tag

    what does that mean? Did you accidentally fire off a nuclear warhead or something? Did you get something you didn't expect or did you not get something that you should have?
    haha, no just a unwanted error!

    We'll I tried:

    Code:
     Dim rNodeinfo As tvTag = CType(NodeInfo.Tag, tvTag)
    and got the Error: Specified cast not valid

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Access object in treeview tag

    It's all in the declarations ....

    vb.net Code:
    1. Dim tv As New tvTag  ' see what I did there?
    2.         tv.Type = "a"
    3.         tv.Index = 1
    4.         TreeView1.Nodes(0).Tag = tv
    5.         Dim tv1 As New tvTag
    6.         tv1 = TreeView1.Nodes(0).Tag
    7.         Label1.Text = tv1.Type & tv.Index.ToString
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  5. #5

    Thread Starter
    Member
    Join Date
    Aug 2012
    Posts
    40

    [RESOVLED]Re: Access object in treeview tag

    I found the problem. I wasn't paying attention to one of the nodes and forgot to set the class to one of them. It still had its string type tag.

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