how to populate a treeviewcontrol?

Stimulsoft Reports.NET discussion
Post Reply
anl1973
Posts: 13
Joined: Tue Jan 17, 2012 11:43 am
Location: Wolfsburg, Germany

how to populate a treeviewcontrol?

Post by anl1973 »

Hi,

I would need to allow a user selecting an objects from a hierarchy (for filtering a report).
Therefore I was about to use a TreeViewControl on a form. Unfortunately I don't really know how to populate the tree inside the control (based on hierarchical data retrieved from a datasource) and how to get the selected value afterwards.
Could you pls give some advice?

BR, Andreas
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: how to populate a treeviewcontrol?

Post by HighAley »

Hello.

We use standard .Net Framework component - TreeView Class.
You could use next code:

Code: Select all

treeView1.Control.Nodes.Add("Parent");
treeView1.Control.Nodes[0].Nodes.Add("Child 1");
treeView1.Control.Nodes[0].Nodes.Add("Child 2");
treeView1.Control.Nodes[0].Nodes[1].Nodes.Add("Grandchild");
treeView1.Control.Nodes[0].Nodes[1].Nodes[0].Nodes.Add("Great Grandchild");
Thank you.
anl1973
Posts: 13
Joined: Tue Jan 17, 2012 11:43 am
Location: Wolfsburg, Germany

Re: how to populate a treeviewcontrol?

Post by anl1973 »

Hi Aleksey,

thx for your answer. Very much appreciated. Got it to work with hard coded values.
Next step would be to populate the tree using (filtered) hierarchical data from a datasource (in fact from two related datasources in my case). I feel I would be able to use proper databands to fetch the records needed to populate the tree but then I would a way to show the form to the user AFTER I have processed some databands.
As far as I understood from the property "Start Mode" available for forms there seems to be no way to display the form in the middle of the report generation.
Alternatively I could use the "Load Form" event of the form to populate the tree (as I did for the hard-coded values) but then I would need a way to fetch the data (including its hierarchy) from the datasources within the code of the event.
Can you pls also give some hints here how this can be achieved?

Many thanks in advance,
Andreas
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: how to populate a treeviewcontrol?

Post by HighAley »

Hello.

Unfortunately, it's impossible to get data this way. The Start mode property set how the form should be displayed but not when it will be shown.
You should prepare the data on your side.

Thank you.
Post Reply