C# 将DGV中的列修改为绑定到数据库的组合框

C# 将DGV中的列修改为绑定到数据库的组合框,c#,sql,workflow-foundation,C#,Sql,Workflow Foundation,我创建了一个名为“FamilyView”的视图来连接两个表(Families和SStatus),并将第一个表(Families)中的id替换为第二个表(SStatus)中的id(该列现在称为“Status”) 此视图现在显示在用户可以修改的datagridview中 Sda = new SqlDataAdapter("Select * from FamilyView",con); Sda.Fill(ds); dg.DataSource = ds.T

我创建了一个名为“FamilyView”的视图来连接两个表(Families和SStatus),并将第一个表(Families)中的id替换为第二个表(SStatus)中的id(该列现在称为“Status”)

此视图现在显示在用户可以修改的datagridview中

        Sda = new SqlDataAdapter("Select * from FamilyView",con);
        Sda.Fill(ds);
        dg.DataSource = ds.Tables[0];
        dg.Refresh();
我想要的是将列单元格“Status”转换为包含来自SStatus的所有名称的组合框

        SqlDataAdapter sadapter = new SqlDataAdapter("Select * From SStatus", con);
        DataSet ds1 = new DataSet();
        sadapter.Fill(ds1);
我发现这个代码:

        DataGridViewComboBoxCell ComboColumn = (DataGridViewComboBoxCell)(dg.Rows[i].Cells[0]);
        ComboColumn.DataSource = ds1.Tables[0];
        ComboColumn.DisplayMember = "Name";
但我不能更换手机

还有这个代码,但我不知道如何使用它:


您的数据源为空:它应该包含两个表:一个包含SStatus,另一个包含族

然后在您的帖子中跟随我的as:

          DataGridViewComboBoxColumn colType = new DataGridViewComboBoxColumn();
        BindingSource wizardBindingSource = new BindingSource();
        wizardBindingSource.DataSource = dataSet; 
        wizardBindingSource.DataMember = "protocol"; // This is the table in the set
        colType.HeaderText = "Type";
        colType.DropDownWidth = 90;
        colType.Width = 90;
        colType.DataPropertyName = "wizardProtocol";
        colType.DataSource = wizardBindingSource;
        colType.DisplayMember = "protocolName";
        colType.ValueMember = "idprotocols"
这里idProtocol(在“pcap”表中被称为协议)映射到protocolName

          DataGridViewComboBoxColumn colType = new DataGridViewComboBoxColumn();
        BindingSource wizardBindingSource = new BindingSource();
        wizardBindingSource.DataSource = dataSet; 
        wizardBindingSource.DataMember = "protocol"; // This is the table in the set
        colType.HeaderText = "Type";
        colType.DropDownWidth = 90;
        colType.Width = 90;
        colType.DataPropertyName = "wizardProtocol";
        colType.DataSource = wizardBindingSource;
        colType.DisplayMember = "protocolName";
        colType.ValueMember = "idprotocols"