Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass data from parent to dialog box

I have a combobox in a dialog box form. I need to fill this combo with the List<> from parent form. How to do that as I cannot pass the List<> via dialog box constructor.

frmChild frm = new frmChild();
frm.ShowDialog();
like image 997
trnTash Avatar asked Sep 01 '25 16:09

trnTash


2 Answers

You can add a property or method on your form, that takes the List<items> and populates the ComboBox.

For example:

List<ItemType> items = GetItemsForFormsComboBox();
frmChild frm = new frmChild();
frm.SetComboItems(items);
frm.ShowDialog();

// in the form
public void SetComboItems(List<ItemType> items)
{
    foreach(var item in items)
    {
        myCombo.Add( /* construct combo item and use item to populate it here */ );
    }
}
like image 92
Rob Avatar answered Sep 04 '25 04:09

Rob


You may make a property of your dialog to get/set List<> data.

like image 23
Arseny Avatar answered Sep 04 '25 04:09

Arseny