ListRows 属性示例ListRows property example

下面的示例使用数值**调节钮** 控制**ComboBox** 的下拉列表中的行数。The following example uses a SpinButton to control the number of rows in the drop-down list of a ComboBox. 用户更改数值调节钮的值, 然后单击ComboBox的下拉箭头以显示列表。The user changes the value of the SpinButton, and then clicks on the drop-down arrow of the ComboBox to display the list.

若要使用此示例,请将此示例代码复制到窗体的 Declarations 部分。To use this example, copy this sample code to the Declarations portion of a form. 确保该窗体包含:Make sure that the form contains:

  • 名为 ComboBox1 的 ComboBoxA ComboBox named ComboBox1.
  • 名为 SpinButton1 的 SpinButtonA SpinButton named SpinButton1.
  • 一个名为"Label1"的 LabelA Label named Label1.
Private Sub UserForm_Initialize() 
 Dim i As Integer 
 For i = 1 To 20 
 ComboBox1.AddItem "Choice " & (ComboBox1.ListCount + 1) 
 Next i 
 SpinButton1.Min = 0 
 SpinButton1.Max = 12 
 SpinButton1.Value = ComboBox1.ListRows 
 Label1.Caption = "ListRows = " & SpinButton1.Value 
End Sub 
Private Sub SpinButton1_Change() 
 ComboBox1.ListRows = SpinButton1.Value 
 Label1.Caption = "ListRows = " & SpinButton1.Value 
End Sub

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.