【问题标题】:Combobox selection filtering datagridview组合框选择过滤datagridview
【发布时间】:2016-07-18 08:25:31
【问题描述】:

我正在尝试使用combobox 过滤datagridview。这个想法是窗口窗体将交易发布到表中,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 中删除绑定源,因为它是通过它填充的?

还有其他方法可以实现吗?

感谢您的宝贵时间。

【问题讨论】:

    标签: c# winforms datagridview combobox


    【解决方案1】:
    var Name =  sidcombo.Items[sidcombo.SelectedIndex].ToString();
    

    【讨论】:

    • 好的,所以将变量添加到 selectedchangecommitted 然后调用使用参数中的变量? - 抱歉对 C# 很陌生
    猜你喜欢
    • 2018-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-08
    • 2012-11-03
    • 1970-01-01
    相关资源
    最近更新 更多