开发者

Form Refreshing Problem in c#

I have two form form A and from B . When user click button on form A , Form B will apperar but Form A is already open .User can set data in form B. When user click add Button in Form B ,the data will pass to form A and textbox in form A will set data with pass data. I received passed data but Form A's textbox not fill with data.How could I do that ?

In Form B add button clik

private void btnAdd_Click(object sender, EventArgs e)
        {

            EmployeeAddressEntity empAdd = new EmployeeAddressEntity();
            empAdd = AddEmployee();

            this.Close();
            NewEmployee emp = new NewEmployee();
            emp.FillAddressGrid(empAd开发者_JS百科d);    

        }

In Form A

public void FillAddressGrid(EmployeeAddressEntity emp)
        {
            txtAddressName.Text = emp.name;

            dgvAddress.Rows.Add(emp.type,emp.name,emp.homephone,emp.fax,emp.email,emp.address,emp.country_id);
            //int a = dgvAddress.Rows.Count;
            dgvAddress.EndEdit();
            dgvAddress.Refresh();
            dgvAddress.Parent.Refresh();

            this.Refresh();
        }


In FormB, define a private field that stores the reference to FormA, and create a custom constructor to pass the reference.

public FormB(FormA form) {
    this.m_FormA = form;
} 

private FormA m_FormA;

When you show FormB from FormA, pass the reference.

using (FormB form = new FormB(this)) {
    form.Show();
}

When you are ready to update FormA, call your member function.

this.m_FormA.FillEmployeeGrid(empAdd);

Once you have all this working, you should not have a need to call Refresh() to update the UI unless something is going to be blocking the UI thread (in which you may want to do some asynchronous anyway).


When you call NewEmployee emp = new NewEmployee(); in form b you are creating a reference to a NEW instance of FORM A (which is 'NewEmployee', right?) but you never actually SHOW this instance. When you invoke emp.FillAddressGrid(empAdd); you are acting on a hidden instance NOT the one which you can see.

When Your create an your instance of form B you need to pass a reference to form B like:

    FormB formB = new FormB();
    formB.Owner = this;
    fromB.show();

This will give you the ability to later call:

((NewEmployee)Owner).FillAddressGrid(empAdd);

from Form B.


so u getting data from form B to form A, Store recieved data in one variable and assign that variable to the textbox. like, textbox1.text=v.tostring();

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜