我有一个带有列表作为数据源的组合框。此列表包含具有其属性(名称,地址等)的对象(客户)。当我选择组合框的一个项目时,我想将信息(地址,邮政编码...)传递给表单上的某些文本框。在我的测试1tier应用程序中,这是正确的。但是我正在开发的主要应用程序是基于MVP的(我对此有自己的看法)。我面临的问题是铸造。由于我的看法不了解我的模型,因此不应允许我使用(客户)。string address = ((Customers)comboBox1.SelectedItem).CustomerAddress;
1层测试代码:
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();
}
}
Run Code Online (Sandbox Code Playgroud)
我已经研究了几天,但没有成功。我希望有人能给我正确的方向。
实际应用程序的代码:
视图:
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
txtName.Text = comboBox1.SelectedValue.ToString(); …Run Code Online (Sandbox Code Playgroud)