close

Adding Items

新增下拉式選單的選項

box.AddItem item[, index]

box    該下拉式選單的物件

item   字串

index   放置該新增字串的位置. 0 在最前面,

 

範例1

combobox1.png

    ComboBox1.AddItem "A"
    ComboBox1.AddItem "B"
    ComboBox1.AddItem "C"

 


範例2

combobox1_1.png

combobox1_2.png

Private Sub CommandButton1_Click()

    ComboBox1.AddItem TextBox1.Value, 2
    
End Sub

 

Removing Items

刪除下拉式選單的選項

box.RemoveItem index

box    該下拉式選單的物件

index   欲刪除選項的位置. 0 在最前面,

範例

 

 

combobox1_5.png

Private Sub CommandButton1_Click()

    ComboBox1.RemoveItem 0
    
End Sub

Clear Items

清空所有選項

box.Clear

範例

combobox1_3.png

Private Sub CommandButton1_Click()

    ComboBox1.Clear


End Sub

 

Getting the value of the currently selected item 

取得正選取選項的值

box.value

box.text

box    該下拉式選單的物件

value  該選單選項的值

text   該選單選項的文字

以上兩種方法都可以

範例

combobox1_6.png

 

方法1 

Private Sub CommandButton1_Click()

    MsgBox ComboBox1.Text
    
End Sub

 

方法2

Private Sub CommandButton1_Click()

    MsgBox ComboBox1.Value
    
End Sub

 

Getting List Items with the List Property

box.List(index)

box    該下拉式選單的物件

index  欲取得選項的位置. 0 在最前面,

範例

combobox1_7.png

 

Private Sub CommandButton1_Click()

    MsgBox ComboBox1.List(0)
    
End Sub

Returning the Number of Items with the ListCount Property

box.ListCount

box    該下拉式選單的物件

範例

combobox1_8.png

Private Sub CommandButton1_Click()

    MsgBox ComboBox1.ListCount
    
End Sub

 

有任何問題歡迎留言給我~~~

 


arrow
arrow

    storynsong01 發表在 痞客邦 留言(3) 人氣()