开发者

Windows Forms combobox.SelectedItem, C#

开发者 https://www.devze.com 2022-12-18 22:23 出处:网络
I have two forms, a combobox is populated on both forms wi开发者_开发百科th this code - **departmentCodeComboBox.Items.Add(\"\");

I have two forms, a combobox is populated on both forms wi开发者_开发百科th 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?


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);
}
}
0

精彩评论

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