Visual Basic 2008 中 Combobox组合框使用方法

1、常用属性

(1)DropDownStyle 组合框的样式

(2)SelectedIndex 当前选定项的索引

(3)SelectedItem 当前选定项

(4)Itmes 该组合框中所包含项的集合

2、Items的属性和方法

(1)count 集合中项个数

(2)Add 添加一个项

(3)Clear 清空所有项

(4)Contains 确定指定项是否在集合中

(5)RemoveAt 删除集合中指定索引处的项

例:

Public Class Form1

Private Sub 载入数据_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 载入数据.Click
Dim i As Integer
For i = 1 To 10
ComboBox1.Items.Add(i)
Next
End Sub

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
MsgBox("当前选中项的索引值为:" & ComboBox1.SelectedIndex)
MsgBox("当前选中项为:" & ComboBox1.SelectedItem)

End Sub

Private Sub 删除当前选中项_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 删除当前选中项.Click
ComboBox1.Items.RemoveAt(ComboBox1.SelectedIndex)
End Sub
End Class

你可能感兴趣的:(combobox)