Solved

HOW TO SKIP EVENTS?

Posted on 1997-12-02
4
299 Views
Last Modified: 2012-06-27
Is it possible to stop some events from occuring?
For example, is it possible to skip the RowColChange event of the grid control when an arrow key is pressed?
0
Comment
Question by:leeal
  • 2
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
dirtdart earned 20 total points
ID: 1443353
You can put code in the event to nullify the action you don't want to happen.  For example, if someone presses the arrow key, and you don't want the RowColChange event to fire, you could place the following code in the Keypress event.

DBGrid1_KeyPress(KeyAscii As Integer)

If KeyAscii = vbArrowKey Then
  'Do whatever you want here
End If

End Sub

Actually, if you wanted to intercept the arrow keys, you would have to use the KeyDown event, which provides you with a keycode instead of an Ascii code.  In this way, you can effectivly eliminate the events that you don't want to fire (or at least the effects of those events).
0
 
LVL 1

Author Comment

by:leeal
ID: 1443354
I am still not quite clear how it's done.

So does it mean that in:

private sub Grid1_KeyPress(KeyAscii as Integer)
   select case KeyAscii
   case 74
      ' do nothing for 'J'
   case 75
      ' do something for 'K'
   end select
end sub

It will skip the subsequent events when 'J' or 'K' is pressed, and NOT skip the subsequent events when any other keys are pressed? Automatically?

Does RowColChange event occur BEFORE or AFTER KeyPress/Up/Down event?

Specifically, what I want to do is to make the Grid NOT to un-highlight the selected regions when arrow keys are pressed.
0
 
LVL 5

Expert Comment

by:dirtdart
ID: 1443355
Actually, it's better to use the KeyDown event.  It intercepts all keys
pressed before they are sent to the form or control for processing.  So, if
you put this code in:

Sub DBGrid1_KeyDown(Keycode As Integer)

If Keycode
= vbRightArrow Then Keycode = 0

End Sub

Then it would intercept that
keypress, and if it is the right arrow, it would turn the keycode into
null, so that the control would think that no key had been pressed.  A list
of keycode constants (vbRightArrow, vbLeftArrow, etc) is available in the
VB help file.

So, RowColChange will fire After the KeyDown and Keypress
events, but before the KeyUp event.

Sorry it took so long for the response, but I was just now able to get on to Expert's Exchange.  Guess they were having server problems.
0
 
LVL 1

Author Comment

by:leeal
ID: 1443356
Thanks.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
message box in access 4 41
SLMGR Switches Are Not Working On KMS Host 3 69
Visual Studio search word table and return Cell index 8 48
How to make an ADE file by code? 11 79
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now