We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Deleting a range of cells

We are using a cell activation of Model.Options.ActivateCurrentCellBehavior = GridCellActivateAction.SelectAll;

With the behaviour, when you enter a cell, it starts editing immediately.

When the user selects a range of cells and deletes, it currently only deletes the contents of the CurrentCell (the one in edit mode). I've tried calling CurrentCell.EndEditing() before the delete is processed, but that did not fix it.

I would like the deletion of a range to work the way it does when Model.Options.ActivateCurrentCellBehavior = GridCellActivateAction.None;

Thank you,
Kyle

3 Replies

HA haneefm Syncfusion Team April 26, 2007 05:46 PM UTC

Hi Kyle,

One way you can do this by handling the CurrentCellKeyDown event of the grid and call the ClearCells method to delete the content from the selected cells in a grid. Here is a code snippet.

private void grid_CurrentCellKeyDown(object sender, KeyEventArgs e)
{
if(e.KeyData == Keys.Delete)
this.grid.Model.ClearCells(this.grid.Model.SelectedRanges,false);
}

Best regards,
Haneef


FC Fabio Cavalcante April 11, 2012 10:13 PM UTC

And how can i move the left over content to the deleted cell?

e.g

Having A1, A2, A3. If i remove A2, A3 should be placed at A2.

THANKS.



MC Mercy C Syncfusion Team May 2, 2012 09:25 AM UTC

Hi Fabio,

Thanks for update.

To move the left over cell contents, please make use of "Rows.RemoveRange()" method to remove the empty space.

void gridControl1_CurrentCellKeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Delete)
{
this.gridControl1.Model.ClearCells(this.gridControl1.Model.SelectedRanges, false);
this.gridControl1.Rows.RemoveRange(this.gridControl1.Model.SelectedRanges.ActiveRange.Top, this.gridControl1.Model.SelectedRanges.ActiveRange.Bottom);
}
}

Please refer to the sample in the following link
http://www.syncfusion.com/downloads/Support/DirectTrac/93412/WindowsFormsApplication91239196294.zip

Regards,
Mercy.C


Loader.
Live Chat Icon For mobile
Up arrow icon