Submit data from child form to parent TextBox form

I have a parent form containing "HUD" with first name, last name, etc. One of the child forms is the search form. When the user selects an item from the results displayed in the DataGrid, I want the relevant information to populate the HUD. I created a HUD class with variables for each value and the UpdateHUD () method. I am not sure how to do this. I have a link to a parent form search form containing a HUD, for example:

public frmWWCModuleHost _frmWWCModuleHost;

This is the code I use to embed forms. I do not use MDI.

 public static void ShowFormInContainerControl(Control ctl, Form frm)
    {
        frm.TopLevel = false;
        frm.FormBorderStyle = FormBorderStyle.None;
        frm.Dock = DockStyle.Fill;
        frm.Visible = true;
        ctl.Controls.Add(frm);
    }

Here is the code that I run on the cell. Click on the search form. This happens before I tried to implement the HUD class.

private void dgvSearchResults_CellContentClick(object sender, DataGridViewCellEventArgs e)
    {
        _frmWWCModuleHost = new frmWWCModuleHost();
        _frmWWCModuleHost.tbxHUD_LastName.Text = dgvSearchResults.CurrentRow.Cells[1].FormattedValue.ToString();
        _frmWWCModuleHost.tbxHUD_LastName.Invalidate();
        _frmWWCModuleHost.FormPaint();
    }

Thanks in advance!

~ Patrick


EDIT


dgvSearchResults_CellContentClick . , , HUD.


EDIT 2


, NEW frmWWCModuleHost ? .


3


"" , : , , . _frmWWCModuleHost = m_parent; UpdateHUD() , _CellClick .

, ; - , ?

+3
3

, "SearchCompleted". - ( ) .

. NotepadCode:

class ParentForm
{
    private readonly ChildForm childForm;

    public ParentForm()
    {
        InitializeComponent();

        childForm = new ChildForm();

        childForm.SearchCompleted += childForm_SearchCompleted;
    }

    private void childForm_SearchCompleted(object sender, SearchCompletedEventArgs e)
    {
        // Update the display
        lblName.Text = e.DataToDisplay;
    }
}

class ChildForm
{
    public event EventHandler<SearchCompletedEventArgs> SearchCompleted;

    private void Search(string query)
    {
        // Do the searching

        OnSearchCompleted(new SearchCompletedEventArgs([arg values]));
    }

    public void OnSearchCompleted(SearchCompletedEventArgs args)
    {
        if (SearchCompleted != null)
        {
            SearchCompleted(this, args);
        }
    }
}
+5

.NET , , .

. , , / ( ).

.

, . , , , ( ), .

+2

, , ( , UpdateHUD ), ( .. UpdateHUD) ( ). , , , .

, , UpdateHUD - , .

private void UpdateHUD(string firstName, string lastName) {
    //...
}

, .

public delegate void HUDUpdateHandler(string firstName, string lastName);

HUDUpdateHandler (, this.handler = handler). , (, t23 > ). UpdateHUD , , .

, , , .

+2

Source: https://habr.com/ru/post/1705729/


All Articles