?
Solved

How do assign a value to a treenode

Posted on 2004-09-29
2
Medium Priority
?
655 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
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
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…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

807 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