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.
Unfortunately, activation email could not send to your email. Please try again.

Checking if a cell is selected

Thread ID:

Created:

Updated:

Platform:

Replies:

79464 Feb 10,2009 04:39 PM Feb 13,2009 09:13 AM Windows Forms 4
loading
Tags: GridControl
Julie Levy
Asked On February 10, 2009 04:39 PM

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


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

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


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

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


Julie Levy
Replied On February 11, 2009 01:18 PM

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


Nisha Arockiya A [Syncfusion]
Replied On February 13, 2009 09:13 AM

Hi Julie,

Thanks for the Update.

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

Regards,
Nisha.


CONFIRMATION

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.

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.

;