Solved

HOW TO SKIP EVENTS?

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JSON Response and request in VB6 application 11 408
Saving history changes to sub form 4 42
vb6 connector to mongodb 2 82
Formula problem with Excel attachment 6 27
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

770 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