简体   繁体   中英

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

Make sure that the event is attached to the FormatComboBox.

By design:

在此处输入图片说明

By Code:

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

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }

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
          }
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM