我在項目中使用MVP,但我是MVP中的新人。 我有兩個組合框。當我在組合框中選擇一個選項時,另一個組合框應該填充新的數據。從演示者(MVP)更新組合框
此操作將在Presenter中進行。我在Presenter中獲得了view'view1',並且在下面的方法中需要'DataSource','DisplayMember','ValueMember'和'Refresh()',並在'view1'中引入了Combobox1和Combobox2屬性。
但是,使用模式時,就足以讓一個屬性像
public string Combobox2
{
get { return comboBox1.SelectedValue.ToSstring(); }
}
到演示者而不是整個組合框。我怎麼解決這個問題?
public void OnSelectedIndexChangedCombobox1()
{
if (view1.Combobox1.SelectedIndex == -1)
{
return;
}
DataTable dt = Tools.GetDataTable("A Path");
var query =
(from o in dt.AsEnumerable()
where o.Field<string>("afield") ==
farmerView.Combobox1.SelectedValue.ToString()
orderby o.Field<string>("anotherfield")
select new KeyValuePair<string, string>(o.Field<string>("field1"),
o.Field<string>("field2"))).ToList();
farmerView.Combobox2SelectedIndexChanged -= OnSelectedIndexChangedCombobox2;
farmerView.Combobox2.DataSource = new BindingSource(query, null);
farmerView.Combobox2.DisplayMember = "Value";
farmerView.Combobox2.ValueMember = "Key";
farmerView.Combobox2.Refresh();
farmerView.Combobox2SelectedIndexChanged +=
OnSelectedIndexChangedCombobox2;
farmerView.Combobox2.SelectedIndex = -1;
}
謝謝