S
Shan1986
Guest
Hallo,
I am using following code given by Mr. Peter Fleischer. When i select an item from the 1st combo box , 2nd and 3rd combo box item changes but none of the event (eg. indexchanged, text changed or valuechanged, etc) for the combo box 2 and 3 are firing. Why?
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Controls.AddRange(New Control() {cb3, cb2, cb1})
Dim bs1 As New BindingSource With {.DataSource = GetDataSet(), .DataMember = "Tab1"}
cb1.DisplayMember = "Master"
cb1.DataSource = bs1
Dim bs2 As New BindingSource With {.DataSource = bs1, .DataMember = "Rel1"}
cb2.DisplayMember = "Child"
cb2.DataSource = bs2
Dim bs3 As New BindingSource With {.DataSource = bs2, .DataMember = "Rel2"}
cb3.DisplayMember = "GrandChild"
cb3.DataSource = bs3
End Sub
Private Function GetDataSet() As DataSet
Dim ds As New DataSet
With ds
With .Tables.Add("Tab1")
With .Columns
.Add("ID", GetType(Integer))
.Add("Master", GetType(String))
End With
End With
With .Tables.Add("Tab2")
With .Columns
.Add("ID", GetType(Integer))
.Add("FKMaster", GetType(Integer))
.Add("Child", GetType(String))
End With
End With
With .Tables.Add("Tab3")
With .Columns
.Add("ID", GetType(Integer))
.Add("FKChild", GetType(Integer))
.Add("GrandChild", GetType(String))
End With
End With
For i = 0 To 9
.Tables("Tab1").Rows.Add(i, $"Master {i + 1}")
For k = i * 10 To i * 10 + 9
.Tables("Tab2").Rows.Add(k, i, $"Child {i + 1}-{k + 1}")
For l = k * 10 To k * 10 + 9
.Tables("Tab3").Rows.Add(l, k, $"Grandchild {i + 1}-{k + 1}-{l + 1}")
Next
Next
Next
.Relations.Add("Rel1", .Tables("Tab1").Columns("ID"), .Tables("Tab2").Columns("FKMaster"))
.Relations.Add("Rel2", .Tables("Tab2").Columns("ID"), .Tables("Tab3").Columns("FKChild"))
End With
Return ds
End Function
Private Sub cb2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cb2.SelectedIndexChanged
MessageBox.Show("selection changed")
End Sub
End Class
I don't see the message "selection changed" when i change something in combo box 1.
Continue reading...
I am using following code given by Mr. Peter Fleischer. When i select an item from the 1st combo box , 2nd and 3rd combo box item changes but none of the event (eg. indexchanged, text changed or valuechanged, etc) for the combo box 2 and 3 are firing. Why?
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Controls.AddRange(New Control() {cb3, cb2, cb1})
Dim bs1 As New BindingSource With {.DataSource = GetDataSet(), .DataMember = "Tab1"}
cb1.DisplayMember = "Master"
cb1.DataSource = bs1
Dim bs2 As New BindingSource With {.DataSource = bs1, .DataMember = "Rel1"}
cb2.DisplayMember = "Child"
cb2.DataSource = bs2
Dim bs3 As New BindingSource With {.DataSource = bs2, .DataMember = "Rel2"}
cb3.DisplayMember = "GrandChild"
cb3.DataSource = bs3
End Sub
Private Function GetDataSet() As DataSet
Dim ds As New DataSet
With ds
With .Tables.Add("Tab1")
With .Columns
.Add("ID", GetType(Integer))
.Add("Master", GetType(String))
End With
End With
With .Tables.Add("Tab2")
With .Columns
.Add("ID", GetType(Integer))
.Add("FKMaster", GetType(Integer))
.Add("Child", GetType(String))
End With
End With
With .Tables.Add("Tab3")
With .Columns
.Add("ID", GetType(Integer))
.Add("FKChild", GetType(Integer))
.Add("GrandChild", GetType(String))
End With
End With
For i = 0 To 9
.Tables("Tab1").Rows.Add(i, $"Master {i + 1}")
For k = i * 10 To i * 10 + 9
.Tables("Tab2").Rows.Add(k, i, $"Child {i + 1}-{k + 1}")
For l = k * 10 To k * 10 + 9
.Tables("Tab3").Rows.Add(l, k, $"Grandchild {i + 1}-{k + 1}-{l + 1}")
Next
Next
Next
.Relations.Add("Rel1", .Tables("Tab1").Columns("ID"), .Tables("Tab2").Columns("FKMaster"))
.Relations.Add("Rel2", .Tables("Tab2").Columns("ID"), .Tables("Tab3").Columns("FKChild"))
End With
Return ds
End Function
Private Sub cb2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cb2.SelectedIndexChanged
MessageBox.Show("selection changed")
End Sub
End Class
I don't see the message "selection changed" when i change something in combo box 1.
Continue reading...