Reputation: 2860
In this project there are multiple reports being generated. Each report can have unlimited subreports, making this a completely recursive solution. I need to make a C# viewer to show these reports, so I made a basic prototype at the moment with a left panel of a treeview and the right panel with a textbox.
My problem is I cannot figure out a way to have the right text populate with the information from the left report (from the tree view) properly. The names of the reports can be duplicates. I was originally adding all of the information to a dictionary with the report names for the keys and the data as the values, but this was not working because of the duplicate titles...
I wanted to use some kind of unique random ID for each report to associate the treenodes with the correct report information, but I seem to be having difficulty doing this. http://msdn.microsoft.com/en-us/library/system.windows.forms.treenode.aspx
From what I have read it doesn't seem like there is some kind of property I can use to do this...How can I make the right textbox populate the information from the report based on the selected treenode on the left side? The treenodes are being added recursively at the moment, and like I said there can be duplicates, so the names of the nodes are not necessarily unique.
Thanks, I will be happy to answer any further questions.
Upvotes: 0
Views: 914
Reputation: 43743
Use the TreeNode.Tag
property to store a reference to the report:
TreeNode node = TreeView1.Nodes.Add(report.Name);
node.Tag = report;
Then, in the AfterSelect
event handler, retrieve the report from the Tag
property of the selected node:
Report report = (Report)e.Node.Tag;
Upvotes: 3