Solved

How do assign a value to a treenode

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

724 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