vba 在具有多列的列表框中添加项目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6973287/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adding items in a Listbox with multiple columns
提问by Andrei Ion
How can I add items in a list with 2 columns
? It adds the items just in the first column if I use ListBox.AddItem
. I want to add items in the 2nd column
too.
Thanks!
如何在列表中添加项目2 columns
?如果我使用ListBox.AddItem
. 我也想添加项目2nd column
。谢谢!
回答by GSerg
By using the List
property.
通过使用该List
属性。
ListBox1.AddItem "foo"
ListBox1.List(ListBox1.ListCount - 1, 1) = "bar"
回答by Srikanth Sharma
There is one more way to achieve it:-
还有一种方法可以实现它:-
Private Sub UserForm_Initialize()
Dim list As Object
Set list = UserForm1.Controls.Add("Forms.ListBox.1", "hello", True)
With list
.Top = 30
.Left = 30
.Width = 200
.Height = 340
.ColumnHeads = True
.ColumnCount = 2
.ColumnWidths = "100;100"
.MultiSelect = fmMultiSelectExtended
.RowSource = "Sheet1!C4:D25"
End With End Sub
Here, I am using the range C4:D25 as source of data for the columns. It will result in both the columns populated with values.
在这里,我使用范围 C4:D25 作为列的数据源。这将导致两个列都填充了值。
The properties are self explanatory. You can explore other options by drawing ListBox in UserForm and using "Properties Window (F4)" to play with the option values.
属性是不言自明的。您可以通过在用户窗体中绘制列表框并使用“属性窗口 (F4)”来处理选项值来探索其他选项。
回答by KONG
select propety
选择属性
Row Source Type => Value List
行源类型 => 值列表
Code :
代码 :
ListbName.ColumnCount=2
ListbName.ColumnCount=2
ListbName.AddItem "value column1;value column2"
ListbName.AddItem "value column1;value column2"