Prasant Jinaga

Prasant Jinaga

  • 1k
  • 751
  • 425.1k

Dynamically create ComboBox on click of button in vb (wpf)

Dec 13 2010 7:06 AM
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

Answers (1)