我有一个下拉框,其数据源为一个包含对象(客户)及其属性(姓名、地址等)的列表。
当我选择下拉框中的某个项目时,我想将信息(地址、邮政编码等)传递到表单上的一些文本框中。
在我的一层测试应用程序中,这个功能是正常工作的。
但是,我正在处理的主要应用程序是基于MVP(带有我的自定义设置)。我面临的问题是类型转换。由于视图不知道我的模型,我不应该使用(客户)代码行:
我是一个能够翻译文本的助手。
我已经花费了几天时间研究这个问题,但一直未能成功。我希望有人能给我正确的方向。
真实应用程序的代码:
视图:
string address = ((Customers)comboBox1.SelectedItem).CustomerAddress;
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();
}
}