Combobox选择过滤datagridview

时间:2016-07-18 08:25:31

标签: c# winforms datagridview combobox

我正在尝试使用datagridview过滤combobox。我们的想法是,窗体将事务发布到表中,datagridview将通过链接到表来显示所选客户的先前交易。

代码:

private void sidcombo_SelectedChangeCommitted(object sender, EventArgs e)
{
    string connectionString = "server=RUBY;" + "initial catalog=CustomerReports;" + "user id=xxxxxxxxxx;" + "password=XXXX";
    SqlConnection conn = new SqlConnection(connectionString);
    string customerselected = ("SELECT * FROM transactions_1617 WHERE customer_ID = @customerid");
    SqlCommand cmd = new SqlCommand(customerselected, conn);
    cmd.Parameters.AddWithValue("@customerid", sidcombo.GetItemText(sidcombo.SelectedValue));
    conn.Open();
    cmd.ExecuteNonQuery();
    conn.Close();
}

我是否需要从DGV中删除绑定源,因为它通过此填充?

还有其他方法来实现这个目标吗?

感谢您的时间。

1 个答案:

答案 0 :(得分:0)

var Name =  sidcombo.Items[sidcombo.SelectedIndex].ToString();