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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trapping the delete key in a Form DataGrid

Status
Not open for further replies.

mbde

Programmer
Mar 14, 2005
55
US
I have seen the sync fusion answer

public class CustomDataGrid : System.Windows.Forms.DataGrid
{
#region Member Variables

#endregion

#region Lifecycle

public CustomDataGrid()
{
}

#endregion


#region Properties
// Added to code, otherwise it does not work
private const int WM_KEYDOWN = 256;

#endregion

#region Methods
public override bool PreProcessMessage( ref Message msg )

{



Keys keyCode = (Keys)(int)msg.WParam & Keys.KeyCode;

if(msg.Msg == WM_KEYDOWN

&& keyCode == Keys.Delete)


{

if(MessageBox.Show("Delete this row?", "", MessageBoxButtons.YesNo) == DialogResult.No)

return true;

}

return base.PreProcessMessage(ref msg);

}


#endregion

And it does not work the first time around. The grid goes into edit mode. The same results with the following code

private void dataGrid1_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete)
{
Console.WriteLine("Key Up Key Data = {0}, Key Value = {1}",e.KeyData.ToString(),e.KeyValue.ToString());
}
}


Can someone explain a solution that will work or why niether of the above code will work the first time around?

I am not alone on this issue

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top