|
■No74348 (モモ さん) に返信
以下のコードでどうでしょう?
Public Class Form1
Private tbl As DataTable
Public Sub New()
' この呼び出しはデザイナーで必要です。
InitializeComponent()
' InitializeComponent() 呼び出しの後で初期化を追加します。
tbl = New DataTable
With tbl.Columns
.Add("val")
.Add("col1")
.Add("col2")
End With
tbl.Rows.Add("01", "abc", "あいう")
tbl.Rows.Add("02", "cde", "かきく")
tbl.Rows.Add("03", "fgh", "さしす")
ComboBox1.ValueMember = "val"
ComboBox1.DisplayMember = "col1"
ComboBox1.DataSource = tbl
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
ComboBox1.DisplayMember = "col1"
Label1.Text = ComboBox1.Text
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
ComboBox1.DisplayMember = "col2"
Label1.Text = ComboBox1.Text
End Sub
End Class
|