问题描述
我有两个 ToolStripCombobox
控件,每个控件都附加了 SelectedIndexChanged
侦听器.
I have two ToolStripCombobox
controls, each with SelectedIndexChanged
listeners attached.
我在以编程方式修改项目集合时遇到问题.我最终不情愿地触发了 SelectedIndexChanged.
I'm facing a problem when I modify the item collection programmatically. I end up triggering the SelectedIndexChanged unwillingly.
在网上搜索解决方案时,我发现了 OnSelectionChangeCommitted 和相应的事件,但 Visual Studio 说:
When searching online for a solution I found OnSelectionChangeCommitted and the corrensponding event, but Visual studio says:
'System.Windows.Forms.ToolStripComboBox.OnSelectionChangeCommitted(System.EventArgs)' is inaccessible due to its protection level.
如果不能使用SelectionChangeCommitted
,手动更新ToolStripComboBox项时,还有什么方法可以避免触发事件?
If it is impossible to make use of SelectionChangeCommitted
, what other ways are there to avoid triggering events when manually updating ToolStripComboBox items?
我使用 .Net 4.0,ToolStripComboBox
配置为 DropDownStyle = DropDownList
.
Im using .Net 4.0 and the ToolStripComboBox
is configured with DropDownStyle = DropDownList
.
推荐答案
您可以从底层 ComboBox 访问它.
You can access it from underlying ComboBox.
toolStripComboBoxExample.ComboBox.SelectionChangeCommitted += ComboBoxOnSelectionChangeCommitted;
private void ComboBoxOnSelectionChangeCommitted(object o, EventArgs eventArgs)
{
\\Your code goes here.
}
这篇关于ToolStripCombobox.SelectionChangeCommitted 未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!