Tab Control Problem

  • Thread starter pawandeep.thind
  • Start date
P

pawandeep.thind

SelectedIndexChanged Event for Tab Control is not fired in .Net
Framework 2.0 but it gets fired in .Net Freamework 1.1 and this
behaviour happens till the form is not shown to the user. After
displaying the form this event starts working fine. Is this a known
problem.
 
M

Mick Doherty

This was a Bug in 1.x that has been fixed in 2.0.
You're obviously a VB.net programmer (like me) because the event didn't fire
in C#.

The reason for the difference was that C# added the handler in the
InitializeComponent method after the SelectedIndex value was set, whereas in
VB the handler was added to a method in the form of Handles
TabControl.SelectedIndexChanged and so this event fired when the value was
set in the InitializeComponent() method.

I expect, but can't say for certain, that the OnSelectedIndexChanged method
of the TabControl was changed to something like:

Protected Overridable Sub OnSelectedIndexChanged(... )
If Me.Created Then
RaiseEvent SelectedIndexChanged(Me, e)
End If
End If

instead of what was probably:

Protected Overridable Sub OnSelectedIndexChanged(... )
RaiseEvent SelectedIndexChanged(Me, e)
End If
 
P

PD

Thankx Mike,

for the input, if what you are saying is correct then it explains the
behaviour that i am experiencing. but, If possible can you provide me
with the details of the bug that you have mentioned in 1.x that got
fixed in 2.0
 
M

Mick Doherty

I'm not sure that it has ever been documented. I personally classify it as a
bug since it was undesired and inconsistent behaviour, but maybe I shouldn't
call it a bug as it was never documented as such.

Furthermore, after a quick look at the methods with reflector, it seems that
no change was made to the OnSelectedIndexChanged method, although several
other methods have been added, so I'm not sure how this was fixed or even if
it was intentional.

I have seen this, let's call it a feature, mentioned several times by people
converting C# code to VB and finding that the code behaved differently. The
workaround was to check if this was the first change and if so don't process
the method, but a better option is to check whether or not the Control has
been created in the SelectedIndexChanged method.

If you want to process the SelectedIndexChanged code when the control is
first shown then simply call the method in the TabControls HandleCreated
event.

Sorry about any confusion that I may have caused with my assumption that it
had been fixed intentionally, when in fact it may have been accidental.
 

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