Controlling Cell Selection Programatically

Hi, I need to make it so the user can only select cells on every third row - clicking on cells between "selectable" rows will select the closest "selectable" cell. I tried the following: grid_CurrentCellActivating(...){ e.RowIndex -= e.RowIndex % 3; } But it didn''t work. What should I be doing? Thanks!

4 Replies

AD Administrator Syncfusion Team September 7, 2005 04:18 PM UTC

Your idea seems to be working in this little sample. What are you doing differently? http://www.syncfusion.com/Support/user/uploads/GC_Paint_9ebcc0a2.zip


CN Clinton Nielsen September 7, 2005 05:13 PM UTC

In my application, there is also the line: this.gridControl1.ListBoxSelectionMode = SelectionMode.MultiExtended; If you add that line to the demo you sent, then you will notice that although the active cell does remain on only the "selectable" lines, the selected cell remains on a "non-selectable" line. What I need is for the selected cell to move as well. Thanks.


AD Administrator Syncfusion Team September 7, 2005 05:49 PM UTC

Try handling the SelectionsChanging event and adjust the selected range there (in addition to handling CurrentCellActivating).
private void gridControl1_SelectionChanging(object sender, GridSelectionChangingEventArgs e)
{
	if(e.Range.IsRows && e.Range.Top % 3 != 1)
	{
		e.Range = GridRangeInfo.Row((e.Range.Top-1) / 3 * 3 + 1);
	}
}


CN Clinton Nielsen September 7, 2005 06:18 PM UTC

Yes. That pretty much does it. There are still a couple circumstances dealing with the Ctrl and Shift keys that cause it to act weird (because in those circumstances, e.Range has a lot of entries), but in general, that solves the problem.

Loader.
Up arrow icon