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

Grid Row Deleting

Hi, We are currently facing a problem in deletion of rows. when the user select rows in sequence all the rows are deleted but if the user tags rows ( i.e select rows holding the ctrl key) only the last selected row gets deleted. Regards Vinay

1 Reply

AD Administrator Syncfusion Team April 8, 2005 09:29 AM

There is special handling required to remove non-contiguous records. As soon as one record is removed, then this may effect the poition of the other records that are selected. The GridDataBoundGrid does not try to handle this. It just deletes the records in the ActiveRange. So if you want this behavior, then you would have to add support for this. You could do it in the RowsDeleting event.
private void grid_RowsDeleting(object sender, GridRowRangeEventArgs e)
{
	GridRangeInfoList rangeList = this.grid.Selections.GetSelectedRows(true, false);
	if(rangeList.Count > 0)
	{
		ArrayList a = new ArrayList();
		CurrencyManager cm = (CurrencyManager)this.grid.BindingContext[this.grid.DataSource, this.grid.DataMember];
		foreach(GridRangeInfo range in rangeList)
		{
			for(int row = range.Top; row <= range.Bottom; ++row)
			{
				int pos = this.grid.Binder.RowIndexToPosition(row);
				a.Add(-pos);
			}
		}
		a.Sort();
		foreach(int pos in a)
		{
			cm.List.RemoveAt(-pos);
		}
		e.Cancel = true;
	}
}

Loader.
Live Chat Icon For mobile
Up arrow icon