Solved

How do assign a value to a treenode

Posted on 2004-09-29
2
639 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 250 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video discusses moving either the default database or any database to a new volume.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now