Creating events

  • Thread starter Thread starter Juan Gabriel Del Cid
  • Start date Start date
J

Juan Gabriel Del Cid

Hi, Richard.

You don't really need to "rasie an event" to add something to the
TreeView. Just pass a reference to your TreeView object (in formA) to formB
and when you click Save (on formB), just add the node.

Hope that helps,
-JG
 
I have 2 forms and one class:

FormA has a TreeView and a Menu.
FormB has a Toolbar and a Textbox.
Class has a property Name and a method Add.

When FormA loads I click on my menu and select New, at this point FormB
loads and I type something in the textbox which calls my class and assigns
the value to the property. When I click on Save it calls a method in my
class which I want it to raise an event to FormA and add the value in my
property to my TreeView. I'm new to C# so I'm having a difficult time
trying to get this to work. Any help would be appreciated. Thanks and have
a nice day!

Richard
 
Richard said:
I have 2 forms and one class:

FormA has a TreeView and a Menu.
FormB has a Toolbar and a Textbox.
Class has a property Name and a method Add.

When FormA loads I click on my menu and select New, at this point FormB
loads and I type something in the textbox which calls my class and assigns
the value to the property. When I click on Save it calls a method in my
class which I want it to raise an event to FormA and add the value in my
property to my TreeView. I'm new to C# so I'm having a difficult time
trying to get this to work. Any help would be appreciated. Thanks and have
a nice day!

Richard

Hard to tell exactly where the problem is from your mailing, but if it's the
events then off the top of my head, the following code should show how one
class declares an event and another responds to it....

public class Document
{
public event EventHandler Saved;
public void Save()
{
//...save code...

if ( Saved != null ){ Saved( this, null ); } //raise the event if anyone
is listening
}
}

public class FormA
{
//constructor
public void FormA(Document doc)
{
doc.Saved += new EventHandler( handleDocumentSaved );
}

void handleDocumentSaved(object sender, EventArgs e)
{
//...redraw tree here perhaps!?...
}
}

HTH

Tobin
 
Back
Top