Keyboard Selection of DataGrid Rows then Delete

W

WineNCheese

Hi all.

I'm having problems preventing the delete of datagrid rows when they are
selected via keyboard selection. I have implemented the common solution of
overriding of PreProcessMessage() to prevent delete when the user selects
the entire row by selecting the row header. This works fine. However,
execution does not enter this method for this scenario:

The user selects a particular value in a particular row/column with the
mouse, and then uses SHIFT-Down Arrow one or more times to select multiple
rows, and then presses delete. Execution does not enter the
PreProcessMessage() method, and the rows get undesireably deleted from the
grid.

BTW, I cannot override ProcessCmdKey() for this either, because this
prevents the use of the delete key within editable columns.

Any ideas?

Thanx!

P.S. I didn't see anything in the DataGrid faq at SyncFusion either,
regarding this.
 
W

WineNCheese

As usual, I'm answering my own question. I can't remember the last post
I've ever done that someone has responded to. Oh well, enough whining.

Anyway, I've got a solution that is good enough for now: I prevent multiple
row selection by eating the key combinations of Shift-Up Arrow, Shift-Down
Arrow, Shift-Page Up, and Shift-Page Down.

WNC
 
G

Guest

I am having similar issue:
Need to disable delete key so it should not delete rows from the datagrid
but they should be able to use the delete ley when editing the cell. Can you
please let me know how you did this.

Thanks
 
C

ClayB [Syncfusion]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top