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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Problem while deleting rows from the grid

Thread ID:

Created:

Updated:

Platform:

Replies:

33356 Aug 18,2005 10:26 AM UTC Aug 22,2005 05:08 PM UTC Windows Forms 3
loading
Tags: GridControl
Manoj
Asked On August 18, 2005 10:26 AM UTC

Hi, We have a grid with 5 rows. As per our functionality, all these five rows are readonly(i.e. the user is not supposed to delete them). At the same time, the user should be able to add new records and if he wishes, he should be able to delete the ones he newly added. But, when the user select an existing row and pressess the delete key, the row is getting deleted by itself(I suppose that is the default behaviour of the grid). I would like to know whether I can prevent the row from getting deleted (by setting some property of the grid etc.)even if the user select the row and pressess the delete key. We tried with the following settings Grid.Binder.EnableRemove = False. But it''s not allowing the user to delete any of the rows in the grid. But as per our functionality, the user should be able to delete the rows he newly added. Thanks Manoj

Administrator [Syncfusion]
Replied On August 18, 2005 12:20 PM UTC

I think to do this, you will have to derive the grid and override HandleCurrentCellKeyDown. Below is code that will not delete any row under 5, but will delete rows after 5. Exactly how you will decide whether a record is a new record or not is up to you. You could track them by primary key for example. You could override OnRowLeave and if e.IsAddNew, then add the primary key value to an arraylist or something, and then test this in the HanleCurrentCellKeyDown override.
public class MyGridDataBoundGrid : GridDataBoundGrid
{
	protected override void HandleBoundCurrentCellKeyDown(KeyEventArgs e)
	{
		if(e.KeyCode == Keys.Delete && !this.CurrentCell.IsEditing)
		{
			if(this.CurrentCell.RowIndex < 5)
			{
				e.Handled = true;
				return;// do not preocess Delete
			}
		}

		base.HandleBoundCurrentCellKeyDown (e);
	}
}

Santha Kumar
Replied On August 22, 2005 02:31 PM UTC

I tried your suggestions, When the row is selected, I am able to prevent the row deletion under 5 and able to delete the row after 5 (newly added rows). We are using OnKeyUp event handler of CellComboBox. Purpose of this handler is to get the AutoComplete Functionality in the CellComboBox for newly added rows. Note: On row deletion OnKeyUp event is not getting fired for either rows under 5 or rows after 5. Our requirement is When the row is selected and it is below 5, onKeyUp event should not get fired to prevent execution of AutoComplete functionality. When the row is selected and it is above 5, onKeyUp event should get fired. This is provide the Autocomplete Functionality. We tried to implement this to cells by removing "this.CurrentCell.IsEditing", Still OnKeyUp event is not getting fired for either rows under 5 or rows after 5.

Administrator [Syncfusion]
Replied On August 22, 2005 05:08 PM UTC

If you want the KeyUp to be hit, try handling the CurrentCellControlKeyMessage event.
private void gridDataBoundGrid1_CurrentCellControlKeyMessage(object sender, GridCurrentCellControlKeyMessageEventArgs e)
{
	Keys keyCode = (Keys) ((int)e.Msg.WParam) & Keys.KeyCode;
	if(keyCode == Keys.Delete)
	{
		e.CallProcessKeyPreview = false;
		e.CallBaseProcessKeyMessage = false;
	}
}

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;