Minor bug in TabControl.TabPages.Remove().

G

Guest

I’ve just found a minor bug in how the TabControl selects the SelectedTab
after you remove a TabPage.

The code from TabControl.ControlCollection.Remove is shown below (thanks
Reflector!) notice that the SelectedIndex is always set even if a different
TabPage was selected previously. For example, I have three TabPages with the
first one selected. I remove the last which sets the SelectedTab to the
second TabPage even though it should stay on the first.

public override void Remove(Control value)
{
base.Remove
(value);
if (!(value is TabPage))
{
return;
}
int num1 = this.owner.FindTabPage((TabPage) value);
if (num1 != -1)
{
this.owner.RemoveTabPage(num1);
this.owner.SelectedIndex = Math.Max((int) (num1 - 1), 0);
}
this.owner.UpdateTabSelection(false);
}
 
B

Bruce Wood

Certainly a bug, but then I think that the whole TabControl / TabPage
thing is a bloody mess to start with. There are myriad problems with
the implementation, and I would be very happy if MS could see their way
clear to fixing them (or creating a whole new pair of classes that are
more usable than these). Some of my beefs include:

"No way" (without resorting to baroque solutions like overriding Paint
methods) to change the font / background colour / etc. etc. of the tabs
themselves--which is what you almost always want to do--but lots of
support for changing the font / background colour / etc. etc. of the
entire page, minus the tab (?)--which is almost never what you want to
do.

Support for ErrorProviders, but no way to show the user that an
ErrorProvider icon is flashing on some control on another tab page.
Flagging an error on a TabPage via an ErrorProvider does absolutely
squat.

No support for hiding, disabling or otherwise showing that a TabPage is
irrelevant in context, other than removing the TabPage from the
control, which is ugly.

No support for putting a TabPage back at an arbitrary point in the page
sequence, so if you make it "disappear" by removing it, you can't put
it back where it was without a lot of messing around, all of which
causes gross flickering and... well, yuck.

Various problems in their interactions with DataBindings: DataBindings
(apparently) don't populate controls that aren't currently visible, so
controls on tab pages other than the one currently selected don't get
populated by DataBindings until the user selects the tab page that
they're on, which can cause all sorts of problems. Well... data
bindings are a mess, too, so it's hard to say whose fault this one is.
:)

Anyway, as I said, I wish that MS would give us new TabPage and
TabControl classes that provide more reasonable functionality than
these ones do. Even if these ones still had no (technical) bugs they
would still be ugly hacks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top