Click here to Skip to main content
15,914,608 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:>
C#
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"]);
        }
    }
}
Posted
Updated 28-Apr-12 5:12am
v2
Comments
VJ Reddy 28-Apr-12 11:12am    
Edit: pre tag for C# code added.

1 solution

In the code given in the question, it is not clear where the TabPage is being selected. However, when a TabPage is selected either programmatically or through the UI, the SelectionChanged event will be fired. As a work around, a public field may be declared in the form as a boolean flag say
C#
bool skipSelectionChangedEvent = false;

Now, in the tabControl1_SelectionChanged event handler, skip the execution of the code if the boolean flag is true.
C#
if (skipSelectionChangedEvent) return;

And before selecting another TabPage programmatically set
C#
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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900