Solved

How do assign a value to a treenode

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

733 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