Solved

HOW TO SKIP EVENTS?

Posted on 1997-12-02
4
296 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

706 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

19 Experts available now in Live!

Get 1:1 Help Now