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

Delete cell data / delete row

1 Answer 85 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Lasse
Top achievements
Rank 1
Lasse asked on 22 Sep 2011, 01:16 PM
Hi,

I want to be able to delete cell data when I hit delete button when the cell only are focused but not in edit mode.
Right now the hole row are deleted. I also want to be able to delete the row, but this should only happen when I have selected the hole row. How can i achieve this kind of functionality?

Regards
Svein Thomas

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 27 Sep 2011, 08:20 AM
Hello Svein,

Thank you for writing.

Your scenario is possible by creating a custom GridDataRowBehavior and override the ProcessDeleteKey method:
class CustomRowBehavior : GridDataRowBehavior
{
    protected override bool ProcessDeleteKey(KeyEventArgs keys)
    {
        this.GridControl.CurrentCell.Value = null;
        return true;
    }
}

Then in RadGridView, unregister the default behavior and register yours:
BaseGridBehavior currentBehavior = radGridView1.GridBehavior as BaseGridBehavior;
currentBehavior.UnregisterBehavior(typeof(GridViewDataRowInfo));
currentBehavior.RegisterBehavior(typeof(GridViewDataRowInfo), new CustomRowBehavior());

The above implementation will set the CurrentCell value to null, when the Delete key is pressed. However, I am not quite sure how would you recognize when a row is fully selected in order to delete a row and when just a cell is selected in order to delete the cell value. Please provide me with the exact end-user scenario of selecting a whole row vs. selecting just a cell, so I can help you with the implementation of this behavior.

I am looking forward to your reply.

All the best,
Stefan
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Lasse
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or