我有一个包含10个列表框的表单。我还有一个命令按钮。如何按下命令按钮,它将选择我选择的列表框的第3项?
答案 0 :(得分:3)
您可以将10个列表框转换为控件数组。如果我没记错的话,您可以为表单中的每个Name
实例指定相同的Index
属性和唯一的非负ListBox
属性。
假设您将所有列表框命名为ListBoxArr
并设置Index
属性,以便第一个列表框为0,第二个列表框为1,等等,那么您可以编写类似这样的内容
' Access the 6th list box and select the third item
' Remember, Index values are zero-based, so 0 is first item...
ListBoxArr(5).ListIndex = 2