ListBox 控件、Column、ColumnCount 和 List 属性示例ListBox control, Column, ColumnCount, List properties example

下面的示例将加载一个包含数据的二维数组, 然后再使用**Column** 和**List** 属性加载两个**ListBox** 控件。The following example loads a two-dimensional array with data and, in turn, loads two ListBox controls using the Column and List properties. 请注意,在加载过程中, Column 属性将转置数组元素。Note that the Column property transposes the array elements during loading.

若要使用此示例,请将此示例代码复制到某窗体的 Declarations 部分。To use this example, copy this sample code to the Declarations portion of a form. 确保该窗体包含两个名为 ListBox1 和 ListBox2 的 ListBox 控件。Make sure that the form contains two ListBox controls named ListBox1 and ListBox2.

Dim MyArray(6,3) 
 
Private Sub UserForm_Initialize() 
 Dim i As Single 
 'The 1st list box contains 3 data columns 
 ListBox1.ColumnCount = 3 
 'The 2nd box contains 6 data columns 
 ListBox2.ColumnCount = 6 
 
 'Load integer values into first column of MyArray 
 For i = 0 To 5 
 MyArray(i, 0) = i 
 Next i 
 
 'Load columns 2 and three of MyArray 
 MyArray(0, 1) = "Zero" 
 MyArray(1, 1) = "One" 
 MyArray(2, 1) = "Two" 
 MyArray(3, 1) = "Three" 
 MyArray(4, 1) = "Four" 
 MyArray(5, 1) = "Five" 
 
 MyArray(0, 2) = "Zero" 
 MyArray(1, 2) = "Un ou Une" 
 MyArray(2, 2) = "Deux" 
 MyArray(3, 2) = "Trois" 
 MyArray(4, 2) = "Quatre" 
 MyArray(5, 2) = "Cinq" 
 
 'Load data into ListBox1 and ListBox2 
 ListBox1.List() = MyArray 
 ListBox2.Column() = MyArray 
 
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.