我有一个列表作为数据源的组合框。此列表包含具有其属性(名称,地址,...)的对象(客户)。 当我选择组合框的一个项目时,我想将信息(地址,邮政编码......)传递给我的窗体上的一些文本框。 在我的测试1tier应用程序中,这是正确的。 但是我正在开发的主要应用程序是基于MVP(凭借我自己的触觉)。我面临的问题是铸造。由于我的观点不知道我的模型,我不应该被允许使用(客户)。 string address = ((Customers)comboBox1.SelectedItem).CustomerAddress;
MVP Winforms和文本框组合框值
1Tier测试代码:
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
//getCustomers((int)comboBox1.SelectedValue);
//txtAddress.Text =Convert.ToString(comboBox1.SelectedValue);
Customers p = (Customers)comboBox1.SelectedItem;
string s = comboBox1.SelectedItem.ToString();
string address = ((Customers)comboBox1.SelectedItem).CustomerAddress;
txtAddress1.Text = address;
}
private void Form3_Load(object sender, EventArgs e)
{
using (var emp = new EmployerEFEntities())
{
var query = from customers in emp.Customers
select customers;
comboBox1.DisplayMember = "CustomerName";
comboBox1.ValueMember = "CustomerID";
comboBox1.DataSource = query.ToList();
}
}
我一直在寻找在这几天了,但还没有来取得成功。我希望有人能给我正确的方向。
实际应用的代码:
查看:
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
txtName.Text = comboBox1.SelectedValue.ToString();
}
private void CustomerView_Load(object sender, EventArgs e)
{
comboBox1.DataSource = customerPresenter.getCustomers();
comboBox1.DisplayMember = "CustomerName";
comboBox1.ValueMember = "CustomerId";
}
主持人:
public List<tbl_customer> getCustomers()
{
using (var customers = new DBCrownfishEntities())
{
var customer = from c in customers.tbl_customer
select c;
return customer.ToList();
}
}