|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
wiring eventsme a little more detail how to "connect up" as mentioned here. Bruce, are you there? Help again, please. 1. If the purpose of MyClass is to interact tightly with a tree view and nothing but a tree view, and that's really all it does, it might be appropriate to pass the tree view instance into MyClass and have it connect up its own event handlers to the events of interest from the tree view. This is a very tight coupling, and you should use it only when MyClass and the tree view are tightly related, one-to-one, and MyClass really doesn't mean anything without a companion tree view. Or, preferably, -- Thanks for your help. Harshad Rathod OK. Got it.
This is what I was trying to do. Please advise if there is any risk. Seems to be working. theTv is a reference to actual treeview that will exist at runtime and this code wil be in a user control. ttheTv is a reference to actual treeview that will exist at runtime. this.theTV.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.tabPage1_theTVAfterSelect); and then have the following.... private void tabPage1_theTVAfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e) { MessageBox.Show(e.Node.Text + " TreeView after select trigerred"); } Show quoteHide quote "Harshad" wrote: > Last month Bruce Wood responded to my question as below. Can some one give > me a little more detail how to "connect up" as mentioned here. > > Bruce, are you there? Help again, please. > > 1. If the purpose of MyClass is to interact tightly with a tree view > and nothing but a tree view, and that's really all it does, it might be > appropriate to pass the tree view instance into MyClass and have it > connect up its own event handlers to the events of interest from the > tree view. This is a very tight coupling, and you should use it only > when MyClass and the tree view are tightly related, one-to-one, and > MyClass really doesn't mean anything without a companion tree view. Or, > preferably, > > > -- > Thanks for your help. > > Harshad Rathod Yes, that's the idea.
I'm assuming that you're passing the tree view into your user control either on the constructor (if the tree view to which it's connected will never change) or via a property or something: public class MyUserControl... { private TreeView theTV; public TreeView AssociatedTreeView { get { return this.theTV; } set { if (this.theTV != null) { this.theTV.AfterSelect -= new System.Windows.Forms.TreeViewEventHandler(this.tabPage1_theTVAfterSelect); } this.theTV = value; if (this.theTV != null) { this.theTV.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.tabPage1_theTVAfterSelect); } } } } Sorry about the long delay. Vacation and all that. :) Thanks Bruce.
Your example is perfect. Show quoteHide quote "Bruce Wood" wrote: > Yes, that's the idea. > > I'm assuming that you're passing the tree view into your user control > either on the constructor (if the tree view to which it's connected > will never change) or via a property or something: > > public class MyUserControl... > { > private TreeView theTV; > public TreeView AssociatedTreeView > { > get { return this.theTV; } > set > { > if (this.theTV != null) > { > this.theTV.AfterSelect -= > new > System.Windows.Forms.TreeViewEventHandler(this.tabPage1_theTVAfterSelect); > } > this.theTV = value; > if (this.theTV != null) > { > this.theTV.AfterSelect += > new > System.Windows.Forms.TreeViewEventHandler(this.tabPage1_theTVAfterSelect); > } > } > } > } > > Sorry about the long delay. Vacation and all that. :) > >
Other interesting topics
Clicking a button and pressing Enter key act different in MDI clie
OT: Replacement for Adobe Acrobat Adding/Updating assemblies in GAC during runtime and not during Se Drag Drop Data pictures to my Form Label with Transparent Background MessageBox and Focus New Thread MessageBox and Form load datagrid memory leak? Obtain default curtom control size |
|||||||||||||||||||||||