选项卡的每个项目上的更改事件触发事件

选项卡的每个项目上的更改事件触发事件

本文介绍了选项卡的每个项目上的更改事件触发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有火的标签控制变化事件,但是当被选择的选项卡中的项事件再次发射.
这是代码的一部分:>

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"]);
        }
    }
}

推荐答案

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.


这篇关于选项卡的每个项目上的更改事件触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 21:16