【问题标题】:SelectedIndexChanged not firing for the ComboBoxSelectedIndexChanged 没有为 ComboBox 触发
【发布时间】:2015-09-17 22:16:49
【问题描述】:

我制作了一个名为 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?

标签: c# winforms combobox


【解决方案1】:

确保事件已附加到 FormatComboBox。

按设计:

按代码:

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

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-26
      • 2012-10-31
      • 2017-02-16
      • 1970-01-01
      • 2012-01-11
      • 2021-04-12
      • 2017-10-28
      • 2011-10-12
      相关资源
      最近更新 更多