Named range selection

Hi Adrian

I'm using the TMS FMX grid to build a simple spreadsheet but am wondering what's the most efficient way to determine if a selected cell or range has an associated name. I see that I can get the named range count then build my own list of named cells/ranges. When I select a cell/range in the grid I can then check if the row/column match those in my list and display the name. Seems a bit clunky though - is there a better way?

Thanks, Bob

There isn't really much more. FlexCel (and Excel) have the named ranges stored on a list that's independent from the cells themselves, so the only way to know if a cell is contained by a named range is to look if it is on the list.

Now, if you want to do it more efficiently, you can first loop over all named ranges and fill a TDictionary<(row, col>, namestring>, where you use a row and a column as a key, and the name as value.
So to find if a cell is inside a named range, you could write:
if NameDict.TryGetValue(TRowColRecord.Create(row, col), name) then

The lookup in the dictionary is going to be near O(1), which is much faster than O(n) from looping in all existing names every time.

Thanks Adrian - the dictionary approach is good.

Cheers, Bob