|
■No66609 (まさ さん) に返信
DB読込は出来ている物として
DataTableを用いたサンプルを載せます。
ComboBox,BindingSourceはデザイナで貼りつけてあるものとします。
Dim tbl1 As New DataTable
With tbl1.Columns
.Add("分類A", GetType(Integer))
.Add("分類A名", GetType(String))
End With
Dim tbl2 As New DataTable
With tbl2.Columns
.Add("分類A", GetType(Integer))
.Add("分類B", GetType(Integer))
.Add("分類B名", GetType(String))
End With
With tbl1.Rows
.Add(1, "りんご")
.Add(2, "みかん")
End With
With tbl2.Rows
.Add(1, 11, "ふじ")
.Add(1, 12, "むつ")
.Add(1, 13, "ジョナ")
.Add(2, 21, "オレンジ")
.Add(2, 22, "伊予かん")
End With
BindingSource1.DataSource = tbl1
ComboBox1.DataSource = BindingSource1
ComboBox1.ValueMember = "分類A"
ComboBox1.DisplayMember = "分類A名"
BindingSource2.DataSource = tbl2
BindingSource2.Filter = "1=0"
ComboBox2.DataSource = BindingSource2
ComboBox2.ValueMember = "分類B"
ComboBox2.DisplayMember = "分類B名"
Private Sub ComboBox1_SelectedValueChanged(sender As Object, e As System.EventArgs) Handles ComboBox1.SelectedValueChanged
BindingSource2.Filter = String.Format("分類A = {0}", ComboBox1.SelectedValue)
End Sub
|