all groups > dotnet windows forms > may 2005 >
You're in the

dotnet windows forms

group:

Delete Key in DataGrid


Delete Key in DataGrid Techstudent
5/13/2005 8:18:07 AM
dotnet windows forms: Hello All,

I Need to disable delete key so it should not delete rows from the datagrid
but should be able to use the delete key when editing the cell. If any one
has any suggestions please let me know.

Thanks
Re: Delete Key in DataGrid ClayB [Syncfusion]
5/14/2005 7:29:03 AM
This Windows Forms FAQ entry shows how you can put up a confirmation
question before deleting the row. You can do the same thing but just not
display the question to ignore the delete key.

George Shepherd's Windows Forms FAQ contains an entry entitled:

How can I put up a confirmation question when the user tries to delete
a row in the datagrid by clicking on the row header and pressing the Delete
key?

Check it out at:
http://www.syncfusion.com/faq/winforms/search/889.asp

=============================================
Clay Burch, .NET MVP

Syncfusion, Inc.
visit http://www.syncfusion.com for .NET Essentials



[quoted text, click to view]

Re: Delete Key in DataGrid ClayB [Syncfusion]
5/14/2005 7:39:59 AM
The solution in the FAQ will not handle this problem.

But here is an derived datagrid using a ProcessCmdKey override. It allows
the delete key to work when editing a cell but ignores it if you try to use
it to delete a row.


public class MyDataGrid : DataGrid
{
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
Keys keyCode = (Keys)(int)msg.WParam & Keys.KeyCode;
if(msg.Msg == 256
&& keyCode == Keys.Delete
&& this.IsSelected(this.CurrentRowIndex)
)
{
//if(MessageBox.Show("Delete this row?", "", MessageBoxButtons.YesNo) ==
DialogResult.No)
return true;
}
return base.ProcessCmdKey (ref msg, keyData);
}
}


=======================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools

[quoted text, click to view]

AddThis Social Bookmark Button