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

Checking if a cell is selected

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


4 Replies

JL Julie Levy 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).

Thanks,
Julie



JJ Jisha Joy Syncfusion Team 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.

Regards,
Jisha



JL Julie Levy 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?

Thanks,
Julie



NA Nisha Arockiya A Syncfusion Team 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.

Regards,
Nisha.


Loader.
Live Chat Icon For mobile
Up arrow icon