vaSpread and Tab

I am using the Farpoint vaSpread 2.5.55 and VB 5.0.  I have a spread with 9 columns.  Whenever the user keys a value and hits "Enter", the spdDetail_LeaveCell event is fired.  This is where I do my validation.  Depending on the column, I do the appropriate validation.  

My problem is that whenever you hit the "Tab" key, it bypasses the spdDetail_LeaveCell event, and no validation occurs.  I have the "Process Tab Key" property set to true, so the focus is moved to the next cell in the spread.  This still results in no spdDetail_LeaveCell event being fired.

I have tried using the spdDetail_KeyDown event, but with funky results.  Any suggestions?  I know, don't use Farpoints Spread!!!

Thanks in advance,
LVL 12
Who is Participating?
jaywalkConnect With a Mentor Commented:
Ok. The tab key is processed by VB _BEFORE_ any messages are sent to your controls. So you can't ever process it. You can achieve the same result, however, by using the following:

Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer

Const VK_TAB = 9&

Private Sub spdDetail_LostFocus()
    If GetKeyState(VK_TAB) And 128 Then
        Debug.Print "Tab was pressed"
    End If
End Sub

The actual specification says "If the most significant bit is set, the key is down".

Of course, if spdDetail doesn't have a LostFocus event, then this isn't going to work. ;p


PreeceAuthor Commented:
I tried your code. spdDetail does have a lostfocus event.  But I am confused as to what the

if GetKeyState(VK_TAB) And 128 then

is supposed to return.  What does 128 represent?  The GetKeyState returned 1 in one test and 0 in another.

PreeceAuthor Commented:
This solution works quite well.  Sorry for the delay!  Thanks for your help.

128 represents 10000000 in binary
-127 comes out as 10000001.

The return values for GetKey(9&) when tab is pressed are one of those two (or should be). The actual documentation says "When the high order bit is set, the key is down".

So if you do a binary 'and' with the result and 128, you get either zero or not zero. True or false. =)

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.