0

我有一个列出 customerID 的 datagridview。我有一个列出客户姓名的组合框。

当我单击 datagridview 时,我知道选择了 customerID,但我无法在组合框中列出此 customerID 的 customerName。

帮助?

private void comboboxFill()
{
    dt = new DataTable();
    OleDbDataAdapter da = new OleDbDataAdapter("Select * from Customers", conn);
    da.Fill(dt);
    dt.Columns.Add("FullName", typeof(String), "CustomerName+' '+CustomerSurName");
    cbx_FullName.ValueMember = "CustomerID";
    cbx_FullName.DisplayMember = "FullName";
    cbx_FullName.DataSource = dt;
}

例如 CustomerID=6 CustomerName="Rocky", CustomerSurName="Balboa" FullName= "Rocky Balboa"

datagridview 上记录的 CustomerID 列表。When select row that CustomerID=6 I wanna to see FullName on cbx_FullName

4

1 回答 1

0

在 datagridview 的 cellclick 事件中

private void dataGridView1_CellClick(object sender,DataGridViewCellEventArgs e)
{
    string firstname = dataGridView1.Rows[e.RowIndex].Cells["CustomerName"].Value.ToString();
    string lastname = dataGridView1.Rows[e.RowIndex].Cells["CustomerSurName"].Value.ToString();
    string ID = dataGridView1.Rows[e.RowIndex].Cells["CustomerID"].Value.ToString();
    string fullname = firstname+" "+lastname;
    cbx_FullName.SelectedIndex = cbx_FullName.Items.IndexOf(fullname);
}
于 2016-05-02T21:07:52.973 回答