public class MyMainForm : System.Windows.Forms.Form, IMessageFilter
{
const int WM_KEYDOWN = 0x100;
const int WM_KEYUP = 0x101;
public bool PreFilterMessage(ref Message m)
{
Keys keyCode = (Keys)(int)m.WParam & Keys.KeyCode;
if(m.Msg == WM_KEYDOWN && keyCode == Keys.Escape)
{
Console.WriteLine("Ignoring Escape...");
return true;
}
return false;
}
....
....
....
private void MyMainForm_Load(object sender, System.EventArgs e)
{
Application.AddMessageFilter(this);
}
}
[C#]
//in formload
this.dataGrid2.DataSource = this.dataSet11.Customers; // set the data source
//make sure grid has a tablestyle
DataGridTableStyle ts = new DataGridTableStyle();
ts.MappingName = this.dataSet11.Customers.TableName;
this.dataGrid2.TableStyles.Add(ts);
//now we can wire up wire up events for columns 1 and 4 ....
DataGridTextBoxColumn tbc = (DataGridTextBoxColumn)ts.GridColumnStyles[0];
tbc.TextBox.KeyPress += new KeyPressEventHandler(CellKeyPress);
tbc = (DataGridTextBoxColumn)ts.GridColumnStyles[3];
tbc.TextBox.KeyPress += new KeyPressEventHandler(CellKeyPress);.....
//the handler
private void CellKeyPress(object sender, KeyPressEventArgs e)
{
//don't allow 1's
if(e.KeyChar == '1')
e.Handled = true;
}