This is a migrated thread and some comments may be shown as answers.

How to avoid Removing a record when press delete key

7 Answers 1420 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Somnath
Top achievements
Rank 1
Somnath asked on 18 Jan 2011, 01:08 PM
Hi,

Please Suggest any way to avoid removing  record from gridview when press delete key;;;
Because, already  I have Delete Button to delete the record from gridview......

7 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 18 Jan 2011, 01:22 PM
Hello,

this will allow you to delete rows programatically (via your button) but not if the user tries to delete via delete key or default context menu.
this.radGridView1.AllowDeleteRow = true;
this.radGridView1.UserDeletingRow += new GridViewRowCancelEventHandler(this.radGridView1_UserDeletingRow);

private void radGridView1_UserDeletingRow(Object sender, GridViewRowCancelEventArgs e)
{
    e.Cancel = true;
}

Hope that helps
Richard
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 18 Jan 2011, 01:34 PM
Apologies.. this should actually be enough if you have a button that programatically deletes the rows

this.radGridView1.AllowDeleteRow = false;

Richard
0
Somnath
Top achievements
Rank 1
answered on 18 Jan 2011, 01:44 PM
Thanks Richard....
This code works better....
0
Eric
Top achievements
Rank 1
answered on 19 Mar 2012, 06:48 PM
Unfortunately this solution does not work with control x (ctrl-x).  As a side note I was expecting ...

gridView.MasterTemplate.AllowDeleteRow = False

... to just work.  I know, I'm too simple :).


Basically, when I use ctrl-x, I don't get the event UserDeletingRow fired, so I can't cancel it.  We've also tried capturing keypress/keydown and cancelling the event, but nothing is seeming to stop the grid from deleting the row.  We have an unbound grid.

So any other suggestions?
0
Stefan
Telerik team
answered on 20 Mar 2012, 09:57 AM
Hi Eric,

Thank you for writing.

The Ctrl+X, Ctrl+C and Ctrl+V commands are a part of the copy/paste functionality of the grid. You can disable this functionality by setting the CopyClipboardMode property:
radGridView1.ClipboardCopyMode = Telerik.WinControls.UI.GridViewClipboardCopyMode.Disable;

I hope that you will find this information useful.
 
All the best,
Stefan
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Eric
Top achievements
Rank 1
answered on 20 Mar 2012, 03:35 PM
Thanks Stefan. It is a bit odd that Telerik provides no way to intercept the Ctrl X in a way that allow us to cancel the row.  I would imagine we are not the developers who would like the ability to throw up a confirmation dialog when a user was about to delete a critical piece of data.  Or simply to allow copy but not delete and/or paste.
0
Stefan
Telerik team
answered on 23 Mar 2012, 04:22 PM
Hello Eric,

Thank you for your suggestion.

Currently, you can stop any of the commands by disabling the whole functionality in the PreviewKeyDown event and the re-enable it in the KeyUp event of RadGridView:
void radGridView1_KeyUp(object sender, KeyEventArgs e)
{
    if (e.Modifiers == Keys.Control && e.KeyCode == Keys.X)
    {
        radGridView1.ClipboardCopyMode = Telerik.WinControls.UI.GridViewClipboardCopyMode.EnableWithoutHeaderText;
    }
}
 
void radGridView1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
    if (e.Modifiers == Keys.Control && e.KeyCode == Keys.X)
    {
        radGridView1.ClipboardCopyMode = Telerik.WinControls.UI.GridViewClipboardCopyMode.Disable;
    }
}

However, your suggestion seems quite reasonable and we will consider improving the functionality with ability to determine which commands are enabled/disabled. I am adding a PITS item for this request. Please follow this link, where you can add your vote for it:http://www.telerik.com/support/pits.aspx#/public/winforms/10420.

I have updated your Telerik points for this suggestion. 

Let us know if you have any other questions or suggestions.

Regards,
Stefan
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Tags
GridView
Asked by
Somnath
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Somnath
Top achievements
Rank 1
Eric
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or