Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

KeyPress Events in DataGrid

Status
Not open for further replies.

stardv

Technical User
May 27, 2004
33
0
0
US
It does not seem they regular key press event work on dataCells in dataGrid
How Can I override DataGrid methods to make it return data cell coordinates when I press enter on it and if it is possible bind it on the “Enter” key press

I am stuck, pleaseeee helppp
 
This is a snippet from Windows Forms FAQ:

Code:
[C#] 
 
public override bool PreProcessMessage( ref Message msg ) 
 
{ 
 
     Keys keyCode = (Keys)(int)msg.WParam & Keys.KeyCode; 
 
     if(msg.Msg == WM_KEYDOWN 
 
          && keyCode == Keys.Delete 
 
          && ((DataView) this.DataSource).AllowDelete) 
 
     { 
 
          if(MessageBox.Show("Delete this row?", "", MessageBoxButtons.YesNo) == DialogResult.No) 
 
               return true; 
 
     } 
 
     return base.PreProcessMessage(ref msg); 
 
} 
 

 
[VB.NET] (courtesy of Erik Johansen) 
 
Public Class DataGrid_Custom 
 
     Inherits DataGrid 
 

 
     Private Const WM_KEYDOWN = &H100 
 

 
     Public Overrides Function PreProcessMessage(ByRef msg As System.Windows.Forms.Message) As Boolean 
 

 
          Dim keyCode As Keys = CType((msg.WParam.ToInt32 And Keys.KeyCode), Keys) 
 
          If msg.Msg = WM_KEYDOWN And keyCode = Keys.Delete Then 
 
               If MessageBox.Show("Delete This Row?", "Confirm Delete", MessageBoxButtons.YesNo) = DialogResult.No Then 
 
                    Return True 
 
               End If 
 
          End If 
 
          Return MyBase.PreProcessMessage(msg) 
 

 
     End Function 
 
End Class

This should help out. Sorry, I can't just kick out C# for your particular problem right about now.

Bryan Wilhite
Songhay System
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top