views:

117

answers:

1

I have two forms, a combobox is populated on both forms with this code -

     **departmentCodeComboBox.Items.Add("");
        foreach (var dept in Departments.GetDepartmentList())
        {
            departmentCodeComboBox.Items.Add(dept);
        }**

When a user clicks the edit button, I want to set the selected item on from2 based on form one.

what is the best way to do this dynamically?

A: 

My suggestion is to have a shared state/model object between formA and formB.

For example :

public class FormB
{
public Department Current{get;set;}
}

public class FormA
{
private void OpenFormB()
{
var selected=departmentcomboBox.SelectedItem;
using(var formB=new FormB{Current=selected})
formB.ShowDialog(this);
}
}
Beatles1692
I'm gonnatry it, what is thte difference between formB.Show() and formB.ShowDialog()?
Alex
When you use ShowDialog method the form will be modal like a dialog box and user should close it to go back to formA.In another words the execution of OpenFormB method will be halted until formB is closed so user can't do anything on FormA until FormB is closed
Beatles1692