Click here to Skip to main content
16,017,857 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Guys

Hope someone can help me.

I have a main Form (Form1) that instantiate a child class (class1).

On my Form1 I have a Treeview.

What I want to do is to change an ImageIndex for my treeview when an event is triggered in my child class?

Is it possible ?

Thanks
Posted

Yes: just add a handler in your Form1 for the event in your class1 instance. When the class signals the event, the form can respond and update the Treeview.
 
Share this answer
 
Comments
Gigantour 10-Oct-11 6:30am    
Thanks for the reply. Do you know of an example on the net maybe?

Thanks in advance
Another way to approach this is to focus on making the TreeView in Form1 available to class1. Since Form1 creates class1, this is easy.

In class1 add a public Property of Type TreeView:
public TreeView ParentTreeView { get; set; }
At the point in your code where Form1 has instantiated class1: insert the reference to the TreeView into class1:
MyClass1 = new class1();
MyClass1.ParentTreeView = Form1.F1TreeView;
Now, your instance of class1 can access Form1's TreeView directly.

If there are, potentially, many subscribers/consumers to/of an Event, consider having the Class raise an Event.

When there are, potentially, many instances of a Class that need access to an Object, consider insertion of an instance of an object (in this case a TreeView).

In this specific case: changing the ImageIndex of a TreeView doesn't require any other external information. If whatever class1 needed to interact with in its parent required many other references, then, of course, using an Event/Subscriber model would be more appropriate.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900