Treeview.Tag property-VBForums
Results 1 to 5 of 5

Thread: Treeview.Tag property

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    58

    Treeview.Tag property

    I am reading through a datatable and setting the text property of the node to a name, and the tag property to a Guid. I want to get both values but I keep getting an error (Object Reference not set to an instance of an object) on the tag property. What is the proper way to get the value from the tag property.
    string s = e.Node.Text;
    string t = e.Node.Tag.ToString();

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    88,977

    Re: Treeview.Tag property

    Your thread title says "TreeView.Tag property", not "TreeNode.Tag property". Are you sure that you're assigning the GUID to the node's Tag property in the first place and not the tree's Tag property? Your error message indicates that that is a possibility.

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,154

    Re: Treeview.Tag property

    I think you may have it there John. If the error says "Object not set to instance blah..." then you need to either step through your code looking to see if its going through your code to set the nodes tag property or place a breakpoint on the code that is setting the nodes tag property and see if it gets executed.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel Core 2 Extreme Ed., 2 WD Raptor 10K RPM 300 GB HDs, 2 GBs DDR2 667 MHz RAM, 2 Viewsonic 24" LCDs, Windows 7 SP-1/Windows 8.1, Office 2010, VS 2013

  4. #4

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    58

    Re: Treeview.Tag property

    Thanks for the quick reply

    what im doing is

    node = treeConsumers.Nodes.Add("ID's");

    foreach (DataRow dr in dtExport.Rows)
    {
    node.Nodes.Add(dr["Last_Name"].ToString().Trim()
    node.Tag = dr["UserGUID"]
    }

    I guess that would set the Tag to the parent node. How do I set it on the child nodes then??

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    88,977

    Re: Treeview.Tag property

    As you can see from your first line, the Add method returns a reference to the node you just added. That means that in the loop the Add method will return a reference to the child node you just added, so you can set its Tag directly:
    Code:
    node.Nodes.Add(dr["Last_Name"].ToString().Trim()).Tag = dr["UserGUID"];

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.