我制作了一个名为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)但即使这样也不起作用
发布于 2015-09-17 22:24:23
确保事件被附加到FormatComboBox。
设计:

By Code:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
comboBox1.SelectedIndexChanged +=comboBox1_SelectedIndexChanged;
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}发布于 2015-09-17 22:26:42
您需要确保在代码或文本框的属性中正确地添加了事件处理程序。它应该是这样的:
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
}
}https://stackoverflow.com/questions/32640827
复制相似问题