Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Key trapping and grid
Message
 
 
To
All
General information
Forum:
ASP.NET
Category:
Forms
Title:
Key trapping and grid
Miscellaneous
Thread ID:
01103330
Message ID:
01103330
Views:
64
Hi All,

I have a form with search criteria on it (including a grid). I'm trying to trying to create a hot key - when I press F5 on this form, I want to call a method of the form that builds a SQL statement and runs it.

I have the form's KeyPreview set to true
I have the following in the form's KeyDown event
private void frmSearch_KeyDown(object sender,System.Windows.Forms.KeyEventArgs e)
{
	switch (e.KeyCode)
	{
		case Keys.Escape :
			this.Close();
			e.Handled=true;
			break;

		case Keys.F5 :			
			this.Search();
			e.Handled=true;
			break;
	}
}
I read thread #1053288 , where Bonnie Berent gives the code to trap for keys, so I created a DataGrid subclass with the following:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
	const int WM_KEYDOWN = 0x100;
	const int WM_SYSKEYDOWN = 0x104;

	if ((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN))
	{
		switch(keyData)
		{
			case Keys.F5 :
				this.EndEdit();
				MessageBox.Show("F5");
				break;
		} //switch
	} //if

	return base.ProcessCmdKey(ref msg,keyData);
}
The messagebox pops open.

Now how do I call the form's Search method from here, or at least use something like SendKeys to pass the key to the form, where the keydown of the form should kick in?

Thanks,
Rick
Rick Hodder
MCP Visual Foxpro
C#, VB.NET Developer
Independent Consultant
www.RickHodder.com
MyBlog
Next
Reply
Map
View

Click here to load this message in the networking platform