Reputation: 1462
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.
Upvotes: 1
Views: 119
Reputation: 82096
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
Upvotes: 1
Reputation: 19790
Not a solution but a different approach: what do you do now when the user selects a row and hit enter?:
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).
Upvotes: 1
Reputation: 4992
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
Upvotes: 0
Reputation: 1783
Can you not set the enabled property to false, and back to true once the data has loaded?
Upvotes: 0