Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a main form "form1" and a second form "searchform"

In main form i have a "Datashow" button for show data from database into textboxs, and a second button "search" for open second form as a dialogBox
I need when i click OK button in second form than second form close and automatically clicked form1's Datashow button

What I have tried:

I need how i clicked main form button automatically by second form button
Posted
Updated 19-Mar-20 7:43am

You don't.
What you do is create your own event in Form2 - call it "ShowData" - which Form1 handles.
You signal the event, Form1 handles it, closes the Form2 instance, and takes the appropriate action - i.e. it calls the same method as it's DataShow button even handler does.

That sounds complicated, but it really isn't - it's how the whole of .NET works, pretty much!
Have a look here: Transferring information between two forms, Part 2: Child to Parent[^] it includes the code you need to modify.
 
Share this answer
 
Just add code after the ShowDialog call to call the DataShow method.
C#
DialogResult dr = searchform.ShowDialog()
if (dr == DialogResult.OK)
{
    DataShow();
}
else
{
// process other response(s)
}
 
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