选项卡的每个项目上的更改事件触发事件 [英] selection Change event fired event on each item of tab
本文介绍了选项卡的每个项目上的更改事件触发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有火的标签控制变化事件,但是当被选择的选项卡中的项事件再次发射.
这是代码的一部分:>
i had fire the tab control change event but when an item of tabs is selected that event fired again.
here the some part of code:>
private void tabControl1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
else if (tabItem3.IsSelected)
{
comboBox2.Items.Clear();
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\shafay\Documents\project001.accdb");
OleDbDataAdapter da = new OleDbDataAdapter("select DeptName from Department ", con);
DataTable dt = new DataTable();
da.Fill(dt);
for (int i = 0; i < dt.Rows.Count; i++)
{
comboBox2.Items.Add(dt.Rows[i]["DeptName"]);
}
}
}
推荐答案
在问题给出的代码中,不清楚在何处选择TabPage
.但是,通过编程方式或通过UI选择TabPage
时,将触发SelectionChanged
事件.解决方法是,可以用以下形式将公共字段声明为布尔标志:
In the code given in the question, it is not clear where theTabPage
is being selected. However, when aTabPage
is selected either programmatically or through the UI, theSelectionChanged
event will be fired. As a work around, a public field may be declared in the form as a boolean flag say
bool skipSelectionChangedEvent = false;
现在,在tabControl1_SelectionChanged
事件处理程序中,如果布尔标志为true,则跳过代码的执行.
Now, in the tabControl1_SelectionChanged
event handler, skip the execution of the code if the boolean flag is true.
if (skipSelectionChangedEvent) return;
并且在选择以编程方式设置的另一个TabPage
之前
And before selecting another TabPage
programmatically set
skipSelectionChangedEvent = true
//Select the Tab page
//Reset the boolean flag to false to enable the SelectionChanged event
skipSelectionChangedEvent = false
希望对您有所帮助.
I hope this may be helpful.
这篇关于选项卡的每个项目上的更改事件触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文