Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 dynamically created combobx on selection changed of list items
Posted
Updated 13-Dec-10 2:25am
v3
Comments
Toniyo Jackson 13-Dec-10 7:06am    
Always put code inside code block.
Toniyo Jackson 13-Dec-10 7:10am    
What error is is showing?
Abdul Quader Mamun 13-Dec-10 8:25am    
Spelling check.

1 solution

The code for adding eventhandler
cbox.SelectionChanged += New AddressOf CreateWPFComboBox

looks like c# kode :)
it should look like this:

AddHandler(cbox.SelectionChanged),AddressOf CreateWPFComboBox   


Furthermore, to be able to use the sub CreateWPFComboBox as an eventhandler for this event, it should look like this:

Private Sub CreateWPFComboBox(ByVal sender As Object, ByVal e As System.Windows.Controls.SelectionChangedEventArgs)
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900