This Example Shows How To Access Data Of Form From Another Form.
By Using This Method You Can Call A Method Or You Can Set Text To TextBox Also.
Normally After Creating A Sub Class You May Have To Access The Parent Class Text Field In Order To Set Or Get The Text To It.Following Example Shows How To Do This.
In My Example I'm Assuming I've Two Forms Called MyForm1 and MyForm2.
MyForm1 Opens The MyForm2.
MyForm1 Have Two Text Fields Called txtInvoiceNo, txtFullName
First Of All Create The Two Forms As Above.
Then We Have To Make The Form1 As Parent Class In Form2.
In Order To Do That We Have To Pass The Form2 Object That Created In Form1(Simply The Form2 Object To Show The Form2)
In Your Form1 You Can Open The Form2 By Clicking A Button Or Any Other Event.Use Following Codes To Do That.Paste The Following Codes In The Event You Are Going To Open The Form2 in Form1.
MyForm2 formMyForm2 = new MyForm2();
formMyForm2.Show();
formMyForm2.RegisterParent(this);//This Code Unit Help To Access This Form From A Object
Add The Following Code Lines Inside The Form2.This Has A MyForm1 Class Object and A Method To Get The Parent Class Object.
private MyForm1 _parent;
internal void RegisterParent(MyForm1 form)
{
this._parent = form;
}
Now You Can Set Your Values From MyForm2 to MyForm1
I'm Using A Button Click Example To Show It.
private void btnAdd_Click(object sender, EventArgs e)
{
//Adding Values To MyForm1
_parent.txtInvoiceNo.Text = "Your Set Code Goes Here";
_parent.txtFullName.Text = "Your Set Code Goes Here";
}
Subscribe to:
Post Comments (Atom)
JWT Token Decode Using Jquery
When it come to authentication we use many mechanism. Ones the user authenticated we must keep these details somewhere safe. So we can share...
-
In this blog post Ill explain you the logic behind the Sri Lankan National Identity Card (NIC). Sri Lanka now has Old NIC No Format as well ...
-
In This Article I Will Demonstrate You To Create A Simple Chat Program Using Java Remote Method Invocation(RMI). Following Program Supports ...
-
In a windows form application sometimes you may want to import a excel file to a data grid view. In this blog post Ill demonstrate to you gu...
No comments:
Post a Comment