ErrorProvider on TabControl

AndyMC

Member
Joined
Feb 12, 2003
Messages
10
I use an ErrorProvider on my form to show errors.
This works fine as long as I dont use a TabControl.

When using a TabControl an error can happen on a TabPage that doesnt have the focus.

So I bring the TabPage with the error to front using this code:

Unfortunately this code brings the TabPage to front but it doesnt show the TabPage as being selected.

Code:
myTabPage.BringToFront()
myTabPage.Select()
myTabPage.Show()
myTabPage.Refresh()

Having TabPage1, TabPage2 and TabPage3 with TabPage3 selected before validation and the error happening on TabPage1 it will show TabPage1 and its controls but it still looks as if TabPage3 would be selected (heading "TabPage3" is in front).

Has anyone an idea to solve this problem?

Thanks in advance
Andy
 
The way to properly bring a tab page to the front is with the SelectedIndex property of the parent tabcontrol.

If you know the tabpage you want, you could do something like this:

Code:
myTabControl.SelectedIndex = myTabControl.TabPages.IndexOf(myTabPage)
 
If you know the names of your TabPage or if you have a reference to that TabPage (as your first sample showed), you can also set the SelectedTab property.

-Nerseus
 
Back
Top