我想为组合框中的值成员分配多个字段。从代码中可以看出,当前分配给 value 成员的字符串是“title”,并且在 cboCustomers_SelectionChangeCommited 事件中,您可以看到一个文本框已经被分配了选定的值。
我希望实现的是将另外两个字段分配给值成员(“名字”、“姓氏”),并为另外两个文本框分配这些值。
我希望我已经清楚了。如果不是,请指定,我将尝试重新解释。
private void Form3_Load(object sender, EventArgs e)
{
try
{
dbConn = new OleDbConnection(conString);
sql = @"SELECT customer.title, firstname, lastname, product.name, account.balance
FROM (account INNER JOIN customer ON account.custid = customer.custid) INNER JOIN product ON account.prodid = product.prodid;";
daItems = new OleDbDataAdapter(sql, dbConn);
daItems.Fill(dtAccBal);
cboCustomers.DataSource = (dtAccBal);
cboCustomers.DisplayMember = "firstname";
cboCustomers.ValueMember = "title";
cboCustomers.SelectedIndex = -1;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error!");
}
}
private void cboCustomers_SelectionChangeCommitted(object sender, EventArgs e)
{
if (cboCustomers.SelectedIndex > -1)
{
try
{
txtTitle.Text = cboCustomers.SelectedValue.ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error!");
}
}
}
}