Home All Groups Group Topic Archive Search About
Author
3 Jan 2005 11:25 PM
Harshad

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

Author
4 Jan 2005 2:59 AM
Harshad
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
Are all your drivers up to date? click for free checkup

Author
20 Jan 2005 11:42 PM
Bruce Wood
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. :)
Author
22 Jan 2005 2:37 AM
Harshad
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. :)
>
>

Bookmark and Share