2020年2月25日 星期二

combobox 下拉式選單

Adding Items

新增下拉式選單的選項

box.AddItem item[, index]
box    該下拉式選單的物件
item   字串
index   放置該新增字串的位置. 0 在最前面,


範例1

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

範例2

Private Sub CommandButton1_Click()

    ComboBox1.AddItem TextBox1.Value, 2
   
End Sub



Removing Items

刪除下拉式選單的選項

box.RemoveItem index

box    該下拉式選單的物件

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

範例

Private Sub CommandButton1_Click()

    ComboBox1.RemoveItem 0
   
End Sub

Clear Items

清空所有選項

box.Clear

範例

Private Sub CommandButton1_Click()

    ComboBox1.Clear


End Sub



Getting the value of the currently selected item

取得正選取選項的值

box.value

box.text

box    該下拉式選單的物件

value  該選單選項的值

text   該選單選項的文字

以上兩種方法都可以

範例

方法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 在最前面,

範例

Private Sub CommandButton1_Click()

    MsgBox ComboBox1.List(0)
   
End Sub

Returning the Number of Items with the ListCount Property

box.ListCount

box    該下拉式選單的物件

範例

Private Sub CommandButton1_Click()

    MsgBox ComboBox1.ListCount
   
End Sub

沒有留言:

張貼留言