Call the Load Event from one form after it has been loaded before
How can a form load event can be called from 1 form to another?
for example say I have two forms. And form1 is my main form and form2 is my ColumnListCheckBox form.
The form2 does the loading when the main form is loaded but if you insert a refresh button so the user can manually refresh the form as well, this should also refresh the load even in the form2. How can this be done?
Thanks!
Kirtan PatelPosted Nov 3, 2009, 6:58 AM
Suppose You have Two Form Form1 and Form 2 . Now Form1 having Button Refresh that Will Refresh The Content of
Running Form2 by Executing its Two Methods "EnablesDisableLoadButton()" and PopulateColumnCheckBox()
then
Form1 Refresh Button Code Would Like Below ( It will call that Two Methods From Running Instance of Form2)
---------------------------------------------------------
private void btnRefresh_Click(object sender, EventArgs e)
{
Form f2RunningInstance = Application.OpenForms["Form2"];
((Form2)f2RunningInstance).EnablesDisableLoadButton();
((Form2)f2RunningInstance).PopulateColumnCheckBox();
}
Form2 Code ( Here Note That those Two Methods Should Be "Public" )
--------------------------------------------------------------------------------------------
private void Form2_Load(object sender, EventArgs e)
{
PopulateColumnCheckBox();
EnablesDisableLoadButton();
}
public void EnablesDisableLoadButton()
{
//Any Code
}
public void PopulateColumnCheckBox()
{
//Any Code
}
friend , if my answer helps you then mark "Do you like this answer " check Box :)
regorPosted Nov 3, 2009, 6:32 AM
Kirtan PatelPosted Nov 3, 2009, 5:54 AM
I think you are doin mistake at locating the instance :)
can Upload your Project Files Zip to http://mediafire.com and Give me download link :)
i will resolve it Quickly and Tell you where you doing mistake in code :)
my mail ID is [email protected]
Happy Coding :)
Nilanka DharmadasaPosted Nov 3, 2009, 5:42 AM
//In your form 2, create a new public method 'LoadMyControls'.
private void ColumnListCheckBox_Load(object sender, EventArgs e)
{
LoadMyControls();
}
public void LoadMyControls()
{
PopulateColumnCheckBox();
EnablesDisableLoadButton();
}
//Then call that new method in form 1.
private ColumnListCheckBox ColumnListCheckBox = new ColumnListCheckBox(); ColumnListCheckBox.LoadMyControls();
If my answer helps you, please accept it.
regorPosted Nov 3, 2009, 5:16 AM
Kirtan PatelPosted Nov 3, 2009, 5:06 AM
your idea to Refresh the Form is not proper :)
you should do this like
1.Write A Function For Code Which you Run At Form_Load Event .
2.after that When you press the refresh Button in Form1 .Locate the Running Instance of Form2 and Execute that Written Function on Form 2 :)
if my answer helps you please check "do you like this answer" :)