Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Label1.Text = If(BindingContext.Contains(d1), _ If(BindingContext(d1).Position < 0, "(nothing)", BindingContext(d1).Current), _ "未割当").ToString() Label2.Text = If(BindingContext.Contains(d2), _ If(BindingContext(d2).Position < 0, "(nothing)", BindingContext(d2).Current), _ "未割当").ToString() End Sub
Private d1 As Integer() = {1, 2, 3, 4, 5} Private d2 As Integer() = {50, 40, 30, 20, 10} Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load ComboBox1.Items.Add("データ1") ComboBox1.Items.Add("データ2") ComboBox2.DataSource = Nothing ComboBox3.DataSource = d1 ComboBox4.DataSource = d2 End Sub Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged If ComboBox1.SelectedIndex = 0 Then ComboBox2.DataSource = d1 Else ComboBox2.DataSource = d2 End If 'ComboBox2.SelectedIndex = If(ComboBox2.Items.Count = 0, -1, 0) End Sub