繁体   English   中英

SelectedIndexChanged不触发ComboBox

[英]SelectedIndexChanged not firing for the ComboBox

我做了一个名为FormatComboBox的组合框。 我用项目列表填充它。 每当用户从列表中选择一个项目时,我都想触发一个事件。 以下是我的代码。

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

我在代码中放置了一个断点,以查看其是否正常工作,并发现无效。 我尝试使用后

private void FormatComboBox_SelectedValueChanged(object sender, EventArgs e)

 private void FormatComboBox_SelectedItemChanged(object sender, EventArgs e)

我是第一次使用C#,并且正在关注本教程

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

他们使用的是以下

private void OnSelectedFormatChanged(object sender, SelectionChangedEventArgs e)

但是即使那样也不起作用

确保该事件已附加到FormatComboBox。

通过设计:

在此处输入图片说明

通过代码:

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

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }

您需要确保实际上在代码或文本框的属性中正确添加了事件处理程序。 它看起来应该像这样:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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