Question problem with ProcessTabKey and combo boxes

erichspecht

New member
Joined
Jan 10, 2010
Messages
4
Programming Experience
10+
Hello. I'm trying to detect when the tab key was pressed and intercept it in certain cases. Since the form I'm working with has many fields, I've tried overriding ProcessTabKey so that I don't have a separate sub for each control. However, I've found that after adding a simple ProcessTabKey method, each time I press tab it skips one of the combo boxes.

In order to duplicate the situation, using Visual Basic Express 2008, create a new Windows Forms project and add 5 combo boxes to the form - allowing each to automatically get an incrementing TabIndex.

Then add the following code the form:

Public Class Form1

Protected Overrides Function ProcessTabKey(ByVal forward As Boolean) As Boolean

MyBase.ProcessTabKey(forward)

End Function

End Class

Now when you run the project, you'll see that each time you press tab it skips one of the combos. Does anyone know a way around this? Any help would be greatly appreciated.

Thanks,

Erich
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,540
Location
Norway
Programming Experience
10+
Now when you run the project, you'll see that each time you press tab it skips one of the combos.
No, I don't see that. Also, the code doesn't change default behavior, so if it's there or not is not relevant. Is your post missing something?
I've tried overriding ProcessTabKey so that I don't have a separate sub for each control
About this, if you mean event handler then one handler sub can handle events for multiple controls.
 

erichspecht

New member
Joined
Jan 10, 2010
Messages
4
Programming Experience
10+
No, I don't see that. Also, the code doesn't change default behavior, so if it's there or not is not relevant. Is your post missing something?

That is what I'm seeing. I put the cursor on the first combo, hit tab, and it moves to the third combo. And you're correct, the code isn't changing the default behavior. This is just to demonstrate the problem I'm experiencing. If I remove that code, the tab order works as expected. I even tried installing Visual Basic Express 2010 to see if this is no longer an issue in that version, but it's occurring in that version as well. Please let me know if anyone has any ideas!
 

erichspecht

New member
Joined
Jan 10, 2010
Messages
4
Programming Experience
10+
Help! Does anyone have any ideas what is wrong?! :)

Please help if anyone knows what might be going wrong here. I've tried this on two computers with VB Express 2008 and VB Express 2010 and it is doing the exact same thing in all environments.

Here's a quick recap:

I've created a windows Forms application, and on the main form added 5 combo boxes. If I run the app, I can tab through them as expected. However, if I add the following code, it skips every other combo box:

Protected Overrides Function ProcessTabKey(ByVal forward As Boolean) As Boolean
MyBase.ProcessTabKey(forward)
End Function

My understanding is that this function should not be changing the behavior. (I'm going to modify this once it's working properly to include a select case statement to switch the tab on a TabControl in certain cases.)

Please let me know if you have any ideas. I'm pulling my hair out!!

Thanks,
Erich :confused:
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,540
Location
Norway
Programming Experience
10+
Actually, when fine-reading the code you posted, I can see the problem; it should be this:
VB.NET:
[B][U]Return[/U][/B] MyBase.ProcessTabKey(forward)
Which means you either typed that yourself, or removed the Return statement from the generated code. If you type 'overrides' and select the ProcessTabKey method in Intellisense dropdown and press Enter then IDE will generate all this for you:
VB.NET:
Protected Overrides Function ProcessTabKey(ByVal forward As Boolean) As Boolean
    Return MyBase.ProcessTabKey(forward)
End Function
The posted code should have resulted in a compiler warning for function missing return value, which VB 2010 does, but I see VB 2008 doesn't complain about this even with that compiler option enabled.
 
Top Bottom