コンボボックスで選択されている項目を取得する方法をご紹介します。
コンボボックスで選択されている値を取得する
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ComboBox1.Items.Add("りんご")
ComboBox1.Items.Add("みかん")
ComboBox1.Items.Add("オレンジ")
End Sub
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
Label1.Text = ComboBox1.SelectedItem
End Sub


ボタン1をクリックすると、
コンボボックスで選択されている項目を取得して、ラベルに表示する例です。
コンボボックスで選択されている項目は、SelectedItemで取得できます。
コンボボックスで選択されている数値を取得する
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ComboBox1.Items.Add(10)
ComboBox1.Items.Add("50")
ComboBox1.Items.Add(100)
End Sub
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
Label1.Text = ComboBox1.SelectedItem + 9
End Sub


数値を扱う場合でも、自動的に判別されますので、不具合は出ません。
もし、期待と異なる結果になる場合には、
文字列から数値へ変換して処理します。
CInt(ComboBox1.SelectedItem)
スポンサーリンク
コンボボックスの項目を全て取得する
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ComboBox1.Items.Add("りんご")
ComboBox1.Items.Add("もも")
ComboBox1.Items.Add("オレンジ")
End Sub
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
Dim str As String
For Each d In ComboBox1.Items
str &= d
Next
Label1.Text = str
End Sub


ボタン1をクリックすると、コンボボックスの項目を全て取得して
ラベルに表示する例です。
コンボボックスの項目を全て取得するには、Itemsを使います。
コンボボックスの全項目数は、Items.Count で取得可能。
また、コンボボックスの各項目にアクセスするには、Items(要素数) と書きます。
これでコンボボックスの値を取得する事ができるようになりました。