Solved

HOW TO SKIP EVENTS?

Posted on 1997-12-02
4
309 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
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…
Suggested Courses
Course of the Month9 days, 11 hours left to enroll

623 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