TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Mayank Jani
NA
477
76.7k
Pass value from one form to another form and refresh.
Jun 17 2017 2:41 AM
Hello,
Greetings of the day...
I am trying to develope a small programme to pass value of one form to another form in C# Windows application. I have one form (the first form) contains 3 textboxes and a command button. when i click the command button, it opens the second form that also contains 3 textboxes and a command button. now when i fill data (like name, age and city) and click on the command button, the second form closes and the data shows in the first form.
my problem is i have to reload the form to display the data in the first form. this way the first form opens twice (i.e. first when programme runs and second when reload to display the values). i found a solution that when i click on first form's command button (to open second form), the first form get closed. but i want to do it without closing thee first form and just REFRESH the first form when second form is closed to transfer the data to first form.
please see my code...
//Code in the First Form
private void btnAdd_Click(object sender, EventArgs e) //to open the second form
{
Form frmPassValuesSub = new frmPassValuesSub();
frmPassValuesSub.Show();
this.Close();
}
private void frmPassValues_Load(object sender, EventArgs e) //to reload to display the values
{
txtReturnName.Text = frmPassValuesSub.SetValueForName;
txtReturnSex.Text = frmPassValuesSub.SetValueForSex;
txtReturnCity.Text = frmPassValuesSub.SetValueForCity;
}
//Code in the Second Form
public static string SetValueForName = ""; //Declaing global variables to store values.
public static string SetValueForSex = "";
public static string SetValueForCity = "";
public frmPassValuesSub()
{
InitializeComponent();
}
private void btnSubmit_Click(object sender, EventArgs e) //Second form to pass values
{
SetValueForName = txtName.Text;
SetValueForSex = txtSex.Text;
SetValueForCity = cmbCity.Text;
Form frmPassValues = new frmPassValues();
frmPassValues.Show();
this.Close();
}
So, i have to close and reopen the first form to avoid the same to open twice (reload to show the data). please suggest me how i can REFRESH the form without closing it.
thank you...
Mayank.
Reply
Answers (
18
)
How to create Rectangle from four coordinates points
how to show data multiple table in crystal report ?