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

Checking if a cell is selected

Thread ID:





79464 Feb 10,2009 09:39 PM UTC Feb 13,2009 02:13 PM UTC WinForms 4
Tags: GridControl
Julie Levy
Asked On February 10, 2009 09:39 PM UTC

When someone clicks on a cell, i need to check whether the cell is selected (in the CellClick event). How can i do this.

Julie Levy
Replied On February 10, 2009 10:41 PM UTC

Actually it seems like CellClick is too late since clicking on an unselected cell automatically selects it. I need to write code to unselect it if selected. By the time CellClick fires there's no way to tell if the user clicked on a selected cell, or if the cell was unselected and automatically selected.

I tried using the SelectionChanging event to set a flag, but it doesn't seem to be firing reliably, or able to tell reliably whether the cell is selected before the user clicks on it with ctrl+left mouse.

What is the best way to know the selected state of the cell when the user clicks on it (Ctrl+Mouse).


Jisha Joy [Syncfusion]
Replied On February 11, 2009 08:42 AM UTC

Hi Julie,

In both GridControl and GridDataBoundGrid classes, there is a member Selections which you can use to access exactly what cells are selected in the grid. This Selections class has a GetSelectedRows method that returns an array of ranges that are selected row ranges. You can then use the Contains method on the the array to see if a particular row range is in the array. Below are code snippets that test whether row 2 is selected.

if (this.gridDataBoundGrid1.Selections.GetSelectedRows(true, false).Contains(GridRangeInfo.Row(2)))
Console.WriteLine("Row 2 is selected");

Please let me know if this helps.


Julie Levy
Replied On February 11, 2009 06:18 PM UTC

Thanks for your response. What is the best event to use to check this? CellClick seems too late.

I think i got it working in the SelectionChanging event using the following to set a flag which i check in the CellClick event.
if (this.Model.Selections.Ranges.AnyRangeContains(e.Range))
{ this.m_bRemoveRange = true;
Do you see anything wrong with this approach?


Nisha Arockiya A [Syncfusion]
Replied On February 13, 2009 02:13 PM UTC

Hi Julie,

Thanks for the Update.

Yes. You can also use SelectionChanging event. Let us know if you find any difficulties.



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