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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Controlling Cell Selection Programatically

Thread ID:





34292 Sep 7,2005 03:03 PM UTC Sep 7,2005 06:18 PM UTC WinForms 4
Tags: GridControl
Clinton Nielsen
Asked On September 7, 2005 03:03 PM UTC

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!

Administrator [Syncfusion]
Replied On 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

Clinton Nielsen
Replied On 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.

Administrator [Syncfusion]
Replied On 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);

Clinton Nielsen
Replied On 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.


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

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