How to Create ComboBox dynamically and add event handler for SelectionChanged event to that dynamically created ComboBox.
I tried this code
Private Sub CreateWPFComboBox()
Dim cbox As New ComboBox()
cbox.Width = 120
cbox.Height = 25
Dim cboxitem1 As New ComboBoxItem()
Dim textitem1 As New TextBox()
cboxitem1.Content = "C# Corner"
cbox.Items.Add(cboxitem1)
Dim cboxitem2 As New ComboBoxItem()
Dim textitem2 As New TextBox()
cboxitem2.Content = "VB.NET Heaven"
cbox.Items.Add(cboxitem2)
textitem2.Text = cboxitem2.ToString()
Dim cboxitem3 As New ComboBoxItem()
Dim textitem3 As New TextBox()
cboxitem3.Content = "MSDN"
cbox.Items.Add(cboxitem3)
textitem3.Text = cboxitem3.ToString()
cbox.SelectionChanged += New AddressOf CreateWPFComboBox
parent.Children.Add(cbox)
End Sub
But Event handler not working it's give me error
so anyone help me how to add event handler to this dynameically created combobx on selection changed of list items
Loading

Bryian TanPosted Dec 13, 2010, 10:44 PM
The correct syntax should be
AddHandler cbox.SelectionChanged, AddressOf combo_SelectionChanged
Private Sub combo_SelectionChanged(ByVal sender As Object, ByVal e As SelectionChangedEventArgs)
'do something
End Sub