Search code examples
c#comboboxselectionchanged

Define SelectionChanged event using C#



I'm trying to define entirely a combobox using C#, however, I got stuck when I want to code the SelectionChanged event.

This is what I've got so far:

ComboBox cmb = new ComboBox();
cmb.Widht=75;
cmb.Margin = new Thickness(20,20,20,20);
cmb.VerticalAlignment = VerticalAlignment.Top;
cmb.HorizontalAlignment = HorizontalAlignment.Left;
cmb.SelectionChanged(cmb,cmb_SelectionChanged);???????
aGrid.Children.Add(cmb);

private void cmb_SelectionChanged(object sender, SelectionChangedEventArgs e){ }

Any idea about what I'm doing wrong here?

Thanks in advance.


Solution

  • Here is the correct code:

    cmb.SelectionChanged += new SelectionChangedEventHandler(cmb_SelectionChanged); 
    

    Regrads