Hello everyone

I have 2 forms frmEmployee and frmSearch. frmSearch is called from frmEmployee
i m not hiding frmEmployee. when i get the focus back of frmEmployee, it seems that textboxes are getting the values from frmSetup but not displaying. Following is the code on frmEmployee

private void btnBrowse_Click(object sender, EventArgs e)
{
frmSearch ObjSearch = new frmSearch(this.Name,this.tbcEmployee.SelectedTab.Name,isLoaded);
 ObjSearch.Show();
 tbEmpid.Text = _empid;
}

The following is the code on frmSearch

private void btnOk_Click(object sender, EventArgs e)
{
    ObjEmployee = new frmEmployee(this.dgvDetail.CurrentRow.Cells[0].Value.ToString());
}

When i debug the program all the controls are populating with the values but the values are not displaying.

What to do?

Thanks and Regards

Recommended Answers

All 4 Replies

In your second code example you create a new frmEmployee (line 3). This new form is not the same as the initial form, so why do you think the initial form would have any data from it?

Ok. I asked this question for a solution. Do u have any?

hey i guess you are a bit confused about using dialog boxes.
when you want to send back information from a child dialog to the main form you dont have to create an instance of the main form again.
what you have to do is set the DialogResult property of the dialog box to true.

so you have to write
this.DialogResult = true;
in frmSearch

now for message passing you can use Application class which is provided by the dot net framework.
in frmsearch you can use:

private void btnOk_Click(object sender, EventArgs e)
{
 Application.Current.Properties["searchResult"] = 
 this.dgvDetail.CurrentRow.Cells[0].Value.ToString();

 this.DialogResult = true;
}

then in frmEmployee you can get the message passed by using:

string info = Application.Current.Properties["searchResult"].ToString();

i guess this may help you.
instead of using the Application class you may also use a static class with static variables for message passing.

Ok. I asked this question for a solution. Do u have any?

1) Yes, I can solve your problem, but I choose to let you solve your own problems as you might actually learn something from it. You don't pay me to provide you with solutions so I'm not obligated to provide them.

2) This question has been asked so many times even the most casual of searches of the internet would have returned thousands of examples of how to solve it. You must not have searched for an answer or you wouldn't have asked, or you don't have the knowledge to understand the answer, which leads to:

3) The solution to this problem is so trivial that anyone who is learning an OO language should know how to do this in the first week. The fact that so many don't means there are a lot of bad classes in OO programming out there. Oddly enough this seems to focus on C# as you don't see this as often in C++/Java. If you are paying to whatever class this is, I'd demand a refund.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.