Overriding ProcessTabKey stops tab working in VB.NET

S

Steve Harrison

Hi,

I have several controls on one VB.NET form, which uses the tabindex to set
the focus in the correct order when tab is pressed. However, if "Yes" is
selected in combo1, and tab is pressed then I want to tab straight to
combo3. Otherwise, the tabbing should behave as normal.

Tab isn't detected on KeyPress or KeyDown events, so I tried this...


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

If combo1.Focused and combo1.Text = "Yes" Then
Combo3.Focus()
Else
'Return False ??
'MyClass.ProcessTabKey(forward) ??
'Me.ProcessTabkey(forward) ??
End If

End Function


....Which works fine when the focus is on combo1 and the text is "Yes", but
when focus is with any other control, pressing tab doesn't work, i.e. the
focus stays where it is.

I think I need to call the parent class which I've overridden to pass any
other condition to be handled normally, but don't know how.

In the above example, "Return False" does nothing, and the other two cause a
StackOverflow, as it's just calling itself rather than back to the base
class.

I remember in Java you could call "this" to pass back to the parent class.

Setting KeyPreview on the form at design time seems to have no effect either

Any ideas how you do it in VB.NET?

Thanks, Steve
 
A

Armin Zingler

Steve Harrison said:
Hi,

I have several controls on one VB.NET form, which uses the tabindex
to set the focus in the correct order when tab is pressed. However,
if "Yes" is selected in combo1, and tab is pressed then I want to
tab straight to combo3. Otherwise, the tabbing should behave as
normal.

Tab isn't detected on KeyPress or KeyDown events, so I tried this...


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

If combo1.Focused and combo1.Text = "Yes" Then
Combo3.Focus()
Else
'Return False ??
'MyClass.ProcessTabKey(forward) ??
'Me.ProcessTabkey(forward) ??
End If

End Function


...Which works fine when the focus is on combo1 and the text is
"Yes", but when focus is with any other control, pressing tab
doesn't work, i.e. the focus stays where it is.

I think I need to call the parent class which I've overridden to
pass any other condition to be handled normally, but don't know how.

In the above example, "Return False" does nothing, and the other two
cause a
StackOverflow, as it's just calling itself rather than back to the
base class.

I remember in Java you could call "this" to pass back to the parent
class.

Setting KeyPreview on the form at design time seems to have no
effect either

Any ideas how you do it in VB.NET?


....
else
return mybase.processtabkey(forward)
end if

See also:
http://msdn.microsoft.com/library/en-us/vbcn7/html/vaconOverridingExistingMethods.asp
(same via <F1>)


Armin
 
L

Larry Lard

I think I need to call the parent class which I've overridden to pass any
other condition to be handled normally, but don't know how.

You want MyBase.ProcessTabKey(forward), I think

MyBase is the VB.NET keyword that is used to call back to a parent
class - you will often see it crop up in overriden procedures.
 

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