Delete cell data / delete row

2 posts, 0 answers
  1. Lasse
    Lasse avatar
    21 posts
    Member since:
    Jul 2011

    Posted 22 Sep 2011 Link to this post

    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
  2. Stefan
    Admin
    Stefan avatar
    2908 posts

    Posted 27 Sep 2011 Link to this post

    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 >>

Back to Top