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

How to tell one cell is selected?

Im trying to find the best or easiest way to tell if one cell is selected. I''ve asked this in the past but I wanted to make sure there wasnt any other ways to do this. I want to be able to tell if the user has clicked ONE and only one cell. So what we came up with today was the following Dim MySelectedRanges As New GridRangeInfoList grdREPA.Selections.GetSelectedRanges(MySelectedRanges, True) Then I check the count of myselectedranges and if its equal 1 then i know i either have one cell selected or i have a ONE range of cells selected. Then i take that further to check myselectedranges.info and if it has a colon(r1c1:r2c2) in it then i know that there is more then one cell. If there is no colon(r1c1), then i know its only one cell in the range selected. Is this the easiest or best way to do this??

3 Replies

AD Administrator Syncfusion Team April 6, 2005 09:04 AM

Do you have grid.ExcelLikeCurrentCell set to true? This setting affects what is selected.


PB Philip Bishop April 6, 2005 09:10 AM

Yes I do


AD Administrator Syncfusion Team April 6, 2005 09:22 AM

Here is how I would try this. It is probably close to what you are doing. I think the code will work whether or not you have ExcelLikeCurrentCell set, and whether or not your grid has a currentcell at all. Whether it is any better than what you are doing, I am not sure.
public bool OnlyCurrentCellSelected()
{
	GridRangeInfoList rangeList = grid.Selections.Ranges;
	bool b = grid.CurrentCell.HasCurrentCell && 
			(rangeList.Count == 0 
			|| (rangeList.Count == 1
				&& grid.ExcelLikeCurrentCell
				&& rangeList.ActiveRange == grid.CurrentCell.RangeInfo
				));
	return b;
}

Loader.
Live Chat Icon For mobile
Up arrow icon