Identify and populate a listbox

前端 未结 3 1893
粉色の甜心
粉色の甜心 2021-01-03 11:26

It\'s a riddle for me: what is the syntax to populate a listbox? But first: how do you identify a listbox? In many forums I read: ListBox1.Additem... But how do

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-03 11:52

    ListBox1.AddItem is for loading a single column ListBox (CodyGrey's answer covers that).

    If you are using a multi column ListBox (property .ColumnCount > 1), then you need to load an Array into .List. The following snippet loads 3 rows into a 2 column ListBox

    Dim dat(0 To 2, 0 To 1) As Variant
    
    dat(0, 0) = "A"
    dat(0, 1) = "B"
    dat(1, 0) = "C"
    dat(1, 1) = "D"
    dat(2, 0) = "E"
    dat(2, 1) = "F"
    
    ListBox1.List = dat
    

    Accessing the List Box: (this will vary for different versions of Word, this is for 2003)

    To access the ListBox properties:

    1. Display the "Control Toolbox" toolbar
    2. Go To Design Mode
    3. Click the control, and select Properties on the "Control Toolbox"
    4. The Name property should now be visible and editable
    5. Other properties, such as ColumnCount etc can also be set

提交回复
热议问题