tags:

views:

33

answers:

3
+1  Q: 

C# Treeview help

Hi,

If I have a treeview being imported into my main program from a dll event. How can I think assign this full Treeview to aTreeview control within my app?

I have the Treeview object from the dll, but I can't figure out how to assign it to the control?

Thanks.

+1  A: 

Just add the instance to the Controls collection of the Form/Control it will be hosted on.

leppie
Would that be the Form1.Designer.cs?
darren young
@darren young: No, you can do it anywhere after InitializeComponents() has been called.
leppie
Hi, thanks for the response, but I am still unsure. I am quite new to C#. So if I have the Treeview control, call it Treeview 1, would I assign as such Treeview1 = _tv; With _tv being the new Treeview?
darren young
@darren young: It should be as simple as `Controls.Add(yourtreeviewfromanotherplace);` You could create a reference to it, if needed, but it is not necessary for it to be added to the host control.
leppie
Thanks, I have it working now.
darren young
A: 

user ready to use component for this propose

Hamid mahmoudzadeh
WTF? Is this your final answer?
leppie
-1 what do you want to say?
Mario The Spoon
A: 

alternatively you should be able to add it to your toolbox and then just drag it onto the canvas/ form. (right-click in toolbox and select elements)

hth

Mario

Mario The Spoon
He mentions he has an instance, not a type. The type I expect to be of `TreeView` anyways.
leppie
Sorry, my bad! I overlooked the 'event' part! My solution only works for types - as you pointed out!
Mario The Spoon