콤보 상자에서 두 개 이상의 필드를 값 멤버에 할당하려고합니다. 코드에서 볼 수 있듯이 value 멤버에 할당 된 현재 문자열은 "title"이며 cboCustomers_SelectionChangeCommited 이벤트에서 텍스트 상자에 선택한 값이 할당 된 것을 볼 수 있습니다.하나의 ComboBox에서 여러 ValueMembers C#
내가 달성하기를 희망하는 것은 value member ("firstname", "lastname")에 할당 된 2 개의 추가 필드가 있고 두 개의 추가 텍스트 상자에이 값이 할당되어 있어야합니다.
나는 분명히했으면 좋겠다. 그렇지 않다면 명시하고 다시 설명하려고 시도 할 것입니다.
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!");
}
}
}
}
그저 잘못되었습니다. 이처럼 여러 값을 가진 드롭 다운 항목을 사용해서는 안됩니다. –
다른 방법을 제안 할 수 있습니까? –