我有一个用户表单和一些带有下拉列表的组合框。然而,其中一个组合框在下拉列表中有近1000个项目,我希望用户能够在组合框中输入一个单词,并根据输入的单词获取可供选择的建议列表,例如,如果他们在组合框中输入'joh'我想向他们显示包含'joh'的下拉菜单中所有选项的列表,以便他们可以选择他们想要的那个。具有近1000个需要上述功能的项目的组合框名为“cboProgrammeName”。我应该说下面的VBA已经提供了这个功能,但并不完全。目前,如果我在组合框中输入'joh',那么我必须单击组合框右侧的箭头,以查看基于'joh'的所有给定建议。但我想要的是VBA自动弹出建议列表而不必单击箭头。那可能吗?我的用户表单有很多vba,但我认为与此问题相关的部分如下。虽然我可以在这里发布我的所有VBA代码,如果它有帮助。提前致谢
Private Sub UserForm_Initialize()
'Add the drop down lists to combo boxes
Dim cProgrammeName As Range
Dim cTaskName As Range
Dim cUserName As Range
Dim ws As Worksheet
Set ws = Worksheets("XXX")
For Each cProgrammeName In ws.Range("ProgrammeNameList")
With Me.cboProgrammeName
.AddItem cProgrammeName.Value
.List(.ListCount - 1, 1) = cProgrammeName.Offset(0, 1).Value
End With
Next cProgrammeName
For Each cTaskName In ws.Range("TaskNameList")
With Me.cboTaskName
.AddItem cTaskName.Value
End With
Next cTaskName
For Each cUserName In ws.Range("UserNameList")
With Me.cboUserName
.AddItem cUserName.Value
End With
Next cUserName
Me.txtDate.Value = "dd/mm/yyyy"
Me.txtComments.Value = "please type text here if required"
Me.cboProgrammeName.SetFocus
Me.cboProgrammeName.Value = "type text to open a list of choices"
Me.cboTaskName.Value = "click the arrow to open a list of choices"
Me.cboUserName.Value = "click the arrow to open a list of choices"
End Sub
答案 0 :(得分:2)
您可以尝试这样的事情......
将以下代码放在UserForm模块上。 如果需要,可以更改工作表和范围引用。
class User < ApplicationRecord
...
has_many :images
has_many :videos
...
has_many :tags
...
end