Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用ADO.Net数据集和TableAdapter使用筛选器填充combox_C#_Ado.net - Fatal编程技术网

C# 使用ADO.Net数据集和TableAdapter使用筛选器填充combox

C# 使用ADO.Net数据集和TableAdapter使用筛选器填充combox,c#,ado.net,C#,Ado.net,我有一个带有数据集和tableadapter的windows窗体 Table1 [id, action, info] Table2 [id, actionId, command] private void cbActions_SelectedIndexChanged(object sender, EventArgs e) { this.optionsTableAdapter.Fill(this.actionsDS.Options); BindingSou

我有一个带有数据集和tableadapter的windows窗体

Table1 [id, action, info]
Table2 [id, actionId, command]

private void cbActions_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.optionsTableAdapter.Fill(this.actionsDS.Options);
        BindingSource source1 = new BindingSource();
        source1.DataSource = actionsDS;
        source1.Filter = "ActionId = " + cbActions.SelectedValue;
        cbOptions.DataSource = source1;
    }
我不知道如何根据第一个组合框(cbActions)过滤sedond组合框(cbOptions)

在sql中,我将使用“选择actionid=5的选项”,但是,为了简单起见,我尝试使用内置的ado.net数据集和数据表


这必须很容易,我必须很接近。

昨天几个小时都在想这件事

int actionId = 5;
            ActionsDS.OptionsDataTable optionsDt = optionsTableAdapter.GetByActionId(actionId);
            cbOptions.DataSource = optionsDt;

处理数据关系可能更简单—您的CardDataSet中有3个表—制造商、型号、修剪。它们之间都有数据关系,比如说它们被命名为ManufactureModel和ModelTrim

打开“数据源”窗口,(查看菜单-其他窗口)并展开每个节点。您将看到制造商、模型和修剪有顶级节点,但在制造商下有模型,在制造商下有修剪(根模型下有另一个修剪)

将制造商拖动到窗体以创建DataGridView,将制造商的子级模型拖动到窗体,并拖动模型的子级修剪

您现在应该有3个bindingsources,但关键是:

  • 制造商bindingsource绑定到数据集表
  • 模型bs绑定到制造商bs,并将datamember设置为ManufacturerModel关系的名称
  • trim bs绑定到模型bs并具有ModelTrim的datamember
运行应用程序;在制造商网格中选择父行会将模型网格过滤为来自该制造商的汽车,并且修剪会细化为仅研磨第一个模型。选择一个型号,并更改饰件等

停止程序(只是为了演示它的工作情况)并将组合框绑定到那些绑定源,删除网格(除非您使用组合框驱动网格,在这种情况下,网格可能更适合您的UI)

不要忘记,只有在数据表中充满数据(这是相关的)的情况下,这才有效-如果有数千家制造商、模型和修剪,这将是一个大数据集(选择性加载会更好,但更复杂)