尝试进行智能组合框项目交互
Trying to make smart combobox item interaction
我来这里是想看看是否可以完成我的想法以节省我编写长代码的时间。
我有 1 个主组合框,其中包含各种项目和一些其他组合框。它们的每个组合框称为 "Combo" + 来自主组合框的项目。
我想知道当我单击某个项目时可以隐藏上次使用的组合框并显示链接到该项目的组合框吗?
1.隐藏上次使用的组合框
2. 显示响应主组合框中所选项目的组合框
Public Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
Dim SelectedAction As String = "Combo" + ComboBox2.Text
lastcombobox.visible = false
' now to assign to the new combobox
lastcombobox = (SelectedAction as name of combobox) combobox
Lastcombobox.visible = true
End Sub
字符串不是控件。字符串是Control.Name的数据类型;那是控制对象的名称属性。您不能将字符串强制转换为控件,但不会丢失所有内容。在设计时创建其他组合框并将它们堆叠在一起。请注意 lastComboBox 之前的 Static 关键字。这会保留对方法调用之间的值。您可以通过将此变量设为 class 级变量来完成同样的事情。第一次调用该方法时,它们在 lastComboBox 中将是空的,因此检查 IsNothhing。 Control.Find return 是一个数组,所以我们必须引用 ctl(0) - 数组的第一个元素,因为我们知道它将 return 只有一个。
Private Sub Combo2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles Combo2.SelectedIndexChanged
Dim SelectedAction As String = "Combo" & Combo2.Text
Static lastComboBox As ComboBox
If Not IsNothing(lastComboBox) Then
lastComboBox.Visible = False
End If
Dim ctl() As Control = Controls.Find(SelectedAction, True)
lastComboBox = CType(ctl(0), ComboBox)
lastComboBox.BringToFront()
lastComboBox.Visible = True
End Sub
我来这里是想看看是否可以完成我的想法以节省我编写长代码的时间。
我有 1 个主组合框,其中包含各种项目和一些其他组合框。它们的每个组合框称为 "Combo" + 来自主组合框的项目。 我想知道当我单击某个项目时可以隐藏上次使用的组合框并显示链接到该项目的组合框吗? 1.隐藏上次使用的组合框 2. 显示响应主组合框中所选项目的组合框
Public Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
Dim SelectedAction As String = "Combo" + ComboBox2.Text
lastcombobox.visible = false
' now to assign to the new combobox
lastcombobox = (SelectedAction as name of combobox) combobox
Lastcombobox.visible = true
End Sub
字符串不是控件。字符串是Control.Name的数据类型;那是控制对象的名称属性。您不能将字符串强制转换为控件,但不会丢失所有内容。在设计时创建其他组合框并将它们堆叠在一起。请注意 lastComboBox 之前的 Static 关键字。这会保留对方法调用之间的值。您可以通过将此变量设为 class 级变量来完成同样的事情。第一次调用该方法时,它们在 lastComboBox 中将是空的,因此检查 IsNothhing。 Control.Find return 是一个数组,所以我们必须引用 ctl(0) - 数组的第一个元素,因为我们知道它将 return 只有一个。
Private Sub Combo2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles Combo2.SelectedIndexChanged
Dim SelectedAction As String = "Combo" & Combo2.Text
Static lastComboBox As ComboBox
If Not IsNothing(lastComboBox) Then
lastComboBox.Visible = False
End If
Dim ctl() As Control = Controls.Find(SelectedAction, True)
lastComboBox = CType(ctl(0), ComboBox)
lastComboBox.BringToFront()
lastComboBox.Visible = True
End Sub