C# 组合框和;列表框

C# 组合框和;列表框,c#,visual-studio,combobox,listbox,C#,Visual Studio,Combobox,Listbox,我的数据集设置如下所示: 可以看出,这两个表之间存在关系 在我的表单页面中,我有以下布局: 组合框只需选择“平台”,我想得到的是列表框仅显示属于关系的记录,并通过plataforma\u id过滤 在“SetupUrlConditions”表的TableAdapter中,我将其设置如下: 当我运行应用程序时,列表框总是显示所有记录,而不是按关系过滤。更改组合框所选项目,结果始终相同 那么,我的代码中是否缺少一些东西来实现这一点 谢谢 编辑: } 好吧,你让我挖那个,因为我已经很久没做了。。

我的数据集设置如下所示:

可以看出,这两个表之间存在关系

在我的表单页面中,我有以下布局:

组合框只需选择“平台”,我想得到的是列表框仅显示属于关系的记录,并通过plataforma\u id过滤

在“SetupUrlConditions”表的TableAdapter中,我将其设置如下:

当我运行应用程序时,列表框总是显示所有记录,而不是按关系过滤。更改组合框所选项目,结果始终相同

那么,我的代码中是否缺少一些东西来实现这一点

谢谢

编辑:

}

好吧,你让我挖那个,因为我已经很久没做了。。。 组合框=平台。要设置的属性是DisplayMember=Plaformas,ValueMember=Id

列表框仅显示成员=条件?。。。由你决定


请记住,此设置始终选择了某些内容。需要对其进行修改,使其最初没有选择任何内容,但超出了问题的范围

仅仅因为为关系配置了数据库并不意味着它将在前端以实物形式响应。您需要引发combobox的changed事件,以强制更新listbox中的结果数据集内容。这种变化将重新填充前端。由于下面的答案需要更多的表单代码,因此我们可以更好地帮助您。现在填充这两个控件。当combobox没有选择时,不要填充listbox
SelectedIndexChange
SelectedValueChanged
事件可用于基于所选值填充列表框。您好@mvermef,我刚刚完成了您指示的操作。我移动了行:this.setupurlconditionstableadter.Fill(this.plataformasdastatset.SetupUrlConditions);在更改事件的组合框中,始终返回所有记录。否将TableAdapters保留在引用我的答案的位置。注意这就像2001年的技术。。。自从WPF问世以来,我还没有真正使用过表单,所以我不得不挠头。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Backoffice
{
    public partial class SetupRules : Form
    {
        public SetupRules()
        {
            InitializeComponent();
        }

        private void plataformasBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.plataformasBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this.plataformasDataSet);

        }

        private void SetupRules_Load(object sender, EventArgs e)
        {

            this.plataformasTableAdapter.Fill(this.plataformasDataSet.plataformas);


            this.setupUrlConditionsTableAdapter.Fill(this.plataformasDataSet.SetupUrlConditions);

        }

}
    private void PlatformasCBO_SelectedValueChanged(object sender, EventArgs e)
    {
        if (PlatformasCBO.SelectedValue != null)
        {
            SiteUrlLstBox.DataSource = this.platformasDataSet.SetupUrlConditions.Where(  p => p.platforma_id == (int)PlatformasCBO.SelectedValue).ToList();
        }
    }