-
Jan 14th, 2007, 07:39 PM
#1
Thread Starter
Member
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();
-
Jan 14th, 2007, 08:41 PM
#2
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.
-
Jan 14th, 2007, 08:45 PM
#3
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!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
-
Jan 15th, 2007, 09:45 PM
#4
Thread Starter
Member
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??
-
Jan 15th, 2007, 09:59 PM
#5
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"];
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
|