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

Ignoring selections on rows

I am trying to do some special handling of selections with the SelectionChanging and SelectionChanged events. I am using the: ListBoxSelectionMode = SelectionMode.MultiExtended; My SelectionChanged code looks something like this (simplyfied): if ( e.Range.Top == 2 ) { e.Cancel = true; } Now the problem is that if my previous selection was say row 3 and 4 and I click row 2. The previous selection is cleared. I'd like to just ignore the click on row 2 and keep the valid selection (3,4). I am sure that must be something simple. Thanks

1 Reply

AD Administrator Syncfusion Team September 11, 2003 11:28 AM UTC

In addition to cancelling the new selection, you also have to cancel the de-selection of the old range which you use e.Range.IsEmpty to test for.
private void gridControl1_SelectionChanging(object sender, GridSelectionChangingEventArgs e)
{
	if(e.Range.IsEmpty && e.ClickRange.IntersectsWith(GridRangeInfo.Row(2)))
		e.Cancel = true;
	else if(e.Range.IntersectsWith(GridRangeInfo.Row(2)))
		e.Cancel = true;
}

Loader.
Live Chat Icon For mobile
Up arrow icon