Click here to Skip to main content
15,901,426 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have three Forms A, B, C

click in FormA to FormB

then click in FormB to FormC

the textBox1 is in FormA, it`s used to display the sum(data) from database;

the dataGridView1 is FormB, it`s used to display the table from database;

FormC is userd to update one of the rows from FormB (means the table from database);



now as the update from FormC .... FormB also change together. the new data is show in FormB and

the database ,what shall i do ,also make a change in FormA`s textBox1(it`s the sum(data))

somebody help!!!!
Posted
Comments
Sergey Alexandrovich Kryukov 9-Jul-11 21:02pm    
Not clear what "click FormA to FormC" means. Tell us what you want to achieve and how it is related to delegates and events.

Please do not post non-answers as solution: will be removed, no one get e-main notifications. Use "Add comment", "Improve question" (use it now!).
--SA

1 solution

If I understand correctly (it's still not too clear), you are trying to coordinate Forms A, B and C so that when one is changed, the information from those forms appears in all of the forms. Correct me if I got that wrong.

If that's what you want to do, then you can create a delegate (in Form A and B?) and pass that to the other form(s). Then when the other forms change, in their event handler for whatever event that occurs when something of interest changed, you call the delegate with the required information that will update the other forms that defined the delegate. In the delegate(s), you update the information in the respective form(s).

For example (please check the syntax, this is just pseudo-code):

In Form A:
// Implement the delegate function to update A when called
void MyFormADelegateHandler(int MyParameterFromB)
{
  // Update Form A with info from MyParameterFromB
  ...
}

  ...
  // Wherever you load Form B, set the delegate in B to call your function
  frmB = new FormB(); // etc.
  frmB.ADelegate = MyFormADelegateHandler;
  frmB.Show();
  ...


Then in Form B:
// Declare the delegate type
public delegate void FormADelegate(int MyParameterFromB);

// Declare a variable to hold the pointer to the delegate function
// I set this to null so it can fail gracefully if no delegate is provided
// That's just how I do it. It may not be necessary, but it's clearer for me.
  public FormADelegate ADelegate = null;

And in the event handler for whatever changed in Form B:
...
// Handle Form B event for whatever changed in Form B
...
// Then call the function passed from Form A
if (ADelegate != null)
{
  ADelegate(MyParameter);
}
...

There might be other ways to do the same thing, but hopefully that should be enough to get you started.
 
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