?
Solved

How do assign a value to a treenode

Posted on 2004-09-29
2
Medium Priority
?
653 Views
Last Modified: 2012-08-13
Ok, im using a treeview to access a bunch of data from a database.... example..

Project
`----LEVEL
`----LEVEL
Project
`----LEVEL
`----LEVEL
`----LEVEL
Project
Project
Project

etc...

Now I have it all populating, but i can't assign the "ID" value to the "leveL' portion, so that when I click on the node I can open up that info pretaining to that level (that is in the database) in say another form, or a datagrid.

Is there away to assign an "ID" or a value that is hidden, and that I can use? sort of like databinding a listview?

This is basically how i fill the tree view..

Private void FillMyTreeView()
{
      ProjectInfo.ProjectInfoPD.GetAllProjectInfo(out ProjectArray);
       
      // Suppress repainting the TreeView until all the objects have been created.
      trvProjectSelect.BeginUpdate();
      
      // Clear the TreeView each time the method is called.
      trvProjectSelect.Nodes.Clear();
            
      // Add a root TreeNode for each Customer object in the ArrayList.
      foreach(ProjectInfo.ProjectInfoPD project in ProjectArray)
      {
            trvProjectSelect.Nodes.Add(new TreeNode(project.GetProjectName()));
         
            //trvProjectSelect.Nodes[ProjectArray.IndexOf(project)].ImageIndex = 1;

            BusinessLayer.Global.aNewProject = project;
            PanelControlSheetPD.GetAllPanelControlInfo(out PanelArray);
            
            // Add a child treenode for each Order object in the current Customer object.
            foreach(PanelControlSheetPD panel in PanelArray)
            {
                  trvProjectSelect.Nodes[ProjectArray.IndexOf(project)].Nodes.Add(
                  new TreeNode(panel.GetLevel() + " - " + panel.GetSubProject() + " - " + panel.GetLot()));
                  
                  trvProjectSelect.Nodes[ProjectArray.IndexOf(project)].Nodes[PanelArray.IndexOf(panel)].ImageIndex = 2;
                  trvProjectSelect.Nodes[ProjectArray.IndexOf(project)].Nodes[PanelArray.IndexOf(panel)].SelectedImageIndex = 2;
            }
      }
                  
      // Begin repainting the TreeView.
      trvProjectSelect.EndUpdate();
}


Thanks in advance...
0
Comment
Question by:jvoros1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 19

Accepted Solution

by:
drichards earned 1000 total points
ID: 12181533
Use the 'Tag' property of the TreeNode.  This assumes it's an int:

   TreeNode tn = new TreeNode(....);
   tn.Tag = <ID>; // get ID value from ???
   trvProjectSelect.Nodes[ProjectArray.IndexOf(project)].Nodes.Add(tn);

Then, when you need it back:

   int ID = (int)tn.Tag; // Where tn is chosen by whatever mechanism you are using
0
 

Author Comment

by:jvoros1
ID: 12182760
awesome, worked perfectly! thanks!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question