Vb.net 从另一个窗体中动态选择combobox

Vb.net 从另一个窗体中动态选择combobox,vb.net,winforms,datagridview,combobox,vb.net-2010,Vb.net,Winforms,Datagridview,Combobox,Vb.net 2010,我在form1中有一个组合框,在另一个form2中有一个datagridview。 我想用第二种形式的datagridview中的值来选择combobox 我在表格2中使用了下面的代码,它是有效的: Private Sub DataGridView1_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.

我在form1中有一个组合框,在另一个form2中有一个datagridview。 我想用第二种形式的datagridview中的值来选择combobox 我在表格2中使用了下面的代码,它是有效的:

   Private Sub DataGridView1_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick

            form1.CBO_fournisseur.Text = DataGridView1.Rows(e.RowIndex).Cells(0).Value.ToString

        Me.Close()

    End Sub
但我想做的是动态传递表单的名称,以避免使用and IFELSE子句来枚举项目中使用form2的所有表单

Private Sub DataGridView1_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick

        If formbon2.Name = "FRM_BN_RECEPTION_CUIR" Then
            FRM_BN_RECEPTION_CUIR.CBO_fournisseur.Text = DataGridView1.Rows(e.RowIndex).Cells(0).Value.ToString

        ElseIf formbon2.Name = "frm_reception_acc_provisoire" Then
            frm_reception_acc_provisoire.CBO_1.Text = DataGridView1.Rows(e.RowIndex).Cells(0).Value.ToString

        End If



        Me.Close()

    End Sub

我想我已经知道你想做什么了。我强烈建议您停止将表单用作共享资源

在表单2中使用如下构造函数:

Private ParentFormCombo as Combobox
Public Sub New(ByVal pCmb as Combobox)
  ParentFormCombo = pCmb
End Sub
然后在双击中,只需更改ParentFormCombo的文本

ParentFormCombo.Text = DataGridView1.Rows(e.RowIndex).Cells(0).Value.ToString
然后你必须停止使用:

FrmList_View.Show()
现在应该始终使用构造函数(New())。因此,请执行以下操作:

Dim f As New FrmList_View(CBO_fournisseur)
'or
Dim f As New FrmList_View(CBO_1)
f.Show()

我很难理解你的要求。你能不能简化一下,或者换个词?此外,我在这篇文章中似乎找不到任何问题:/Sorry@WozzeC:)我编辑了我的问题。希望我能更明确一些谢谢你,你救了我。这正是我需要的