Kenneth Joseph Paul
Kenneth Joseph Paul

Reputation: 2211

SelectedIndexChanged not firing for the ComboBox

I made a combobox with the name FormatComboBox. I populated it with a list of items. I want to trigger an event whenever the user selects an item from the list. The following is my code.

 private void FormatComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
              /// some code
        }

I put a break point inside the code to see whether it is working and found that it isn't. After I tried using

private void FormatComboBox_SelectedValueChanged(object sender, EventArgs e)

 private void FormatComboBox_SelectedItemChanged(object sender, EventArgs e)

I am working on c# for the first time and I was following this tutorial

http://www.kinectingforwindows.com/2013/04/09/tutorial-kinect-television/

The one they used was the following

private void OnSelectedFormatChanged(object sender, SelectionChangedEventArgs e)

But even that is not working

Upvotes: 1

Views: 2720

Answers (2)

Hooplator15
Hooplator15

Reputation: 1550

You need to make sure that you are actually adding the event handler properly in your code or in the text box's properties. It should look something like this:

    public partial class Form1 : Form
        {
            FormatComboBox fbox = new FormatComboBox();

            // Associate event handler to the combo box.
            fbox.SelectedValueChanged+=FormatComboBox_SelectedValueChanged;

        prviate void FormatComboBox_SelectedIndexChanged(object sender, EventArgs e)
          {
              // do stuff
          }
        }

Upvotes: 3

JGV
JGV

Reputation: 5197

Make sure that the event is attached to the FormatComboBox.

By design:

enter image description here

By Code:

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            comboBox1.SelectedIndexChanged +=comboBox1_SelectedIndexChanged;
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }

Upvotes: 7

Related Questions