brian4342
brian4342

Reputation: 1253

how to execute code when the tab index changes?

I currently have a tabcontrol on my windows form in visual studio, i would like it so that when the user clicks on a different tab that i can execute some code (for example populate a listbox).

when i double click on the tab it only brings up an onclick event for the body of the tabcontrol.

i was thinking that i may have to create a thread in the form load that will constantly check whether the tab index changes and if it does then execute some code. but surely there must be an easier way?

Upvotes: 0

Views: 6883

Answers (2)

Adil
Adil

Reputation: 148120

You can use TabControl.Selecting or TabControl.SelectedIndexChanged event

private void tabControl1_Selecting(object sender, TabControlCancelEventArgs e)
{
     //Your code goes here.
}

Upvotes: 3

Related Questions