views:

65

answers:

4

Hello, I have a Winforms DataGridView in my application. When the user selects a row and hits enter, I load a new form with details related to that row. It takes about a second to get the data and show the screen. Some of the users are pretty fast and they start entering keystrokes relevant to the form e.g Pg Down/Pg Up, even before it loads and complain that the grid scrolls down instead of seeing the intended effect on the loaded Form.

I need a way to pause the keystroke messages from being processed until the form is loaded. Any ideas highly appreciated.

A: 

Can you not set the enabled property to false, and back to true once the data has loaded?

amarsuperstar
I already thought this. Would'nt I lose the keystroke info if I do this?
SKG
The users will still complain saying they don't see the intended operation in the loaded form
SKG
A: 

A simple bool check should do.

Create a bool, name it 'busy', and when the enter button is pressed check it to true.

if (!busy)
{
busy = true;
//do your thing
}

Simply check it back to false again when the loading is finished

Pieter888
+1  A: 

You could capture the WM_KEYDOWN message and ignore it if the form is loading (perhaps setting a flag) or you could post the messages to the currently loading form.

Have a look at IMessageFilter

James
Can you elaborate on how I can post this to the new form after it is loaded?
SKG
+1  A: 

Not a solution but a different approach: what do you do now when the user selects a row and hit enter?:

  1. Show form and load data
  2. load data and show form

Option 1 is best combined with a loading icon/message. If you really have to enable the keystrokes then capture them and refire them when you are done loading. The new form will receive the keystrokes because it's topmost and active (if done correctly).

PoweRoy
In my current approach I bind the data first and then make the form visible. I am having the "Capture them and refire" approach you mentioned. Not sure how to go about implementing it.
SKG