How can I do inverse selection in AdvStringGrid (TMS)?
Asked
Active
Viewed 1,359 times
2
-
1please put some effort into explaining what you mean – David Heffernan Oct 08 '11 at 17:09
-
1Something like this ? [disjunct cell selection](http://www.tmssoftware.com/site/asg48.asp) – LU RD Oct 08 '11 at 19:26
-
1I think OP means he wants to inverse the selection. Is it really that hard to understand? +1 – NGLN Oct 08 '11 at 22:32
-
E.g. in a 1 by 4 grid in which cells 2 and 3 are currently selected, cells 1 and 4 have to be selected instead. – NGLN Oct 08 '11 at 22:33
-
2"**invert** selection" maybe? – Premature Optimization Oct 09 '11 at 00:51
1 Answers
4
Assuming, that NGLN is right, you'll need to set the proper Disjunct...Select option in Grid.MouseActions to select the kind of selection you'll allow, and then you can call this procedure:
PROCEDURE InvertSelection(Grid : TAdvStringGrid);
VAR
C,R : Cardinal;
BEGIN
IF Grid.MouseActions.DisjunctCellSelect THEN
FOR R:=Grid.FixedRows TO PRED(Grid.RowCount) DO FOR C:=Grid.FixedCols TO PRED(Grid.ColCount) DO Grid.SelectedCells[C,R]:=NOT Grid.SelectedCells[C,R]
ELSE IF Grid.MouseActions.DisjunctRowSelect THEN
FOR R:=Grid.FixedRows TO PRED(Grid.RowCount) DO Grid.RowSelect[R]:=NOT Grid.RowSelect[R]
ELSE IF Grid.MouseActions.DisjunctColSelect THEN
FOR C:=Grid.FixedCols TO PRED(Grid.ColCount) DO Grid.ColSelect[C]:=NOT Grid.ColSelect[C]
END;
This will make all unselected rows/columns/cells selected and vice-versa.

HeartWare
- 7,464
- 2
- 26
- 30
-
Sorry, but this function doesn't work. Do you try to use this code? – YoungMaster Oct 11 '11 at 09:35
-
@YoungMaster, I've tested it and it works. You probably missed the part how to set the `MouseActions.DisjunctCellSelect` or `MouseActions.DisjunctRowSelect` or `MouseActions.DisjunctColSelect` property to `True` on your `TAdvStringGrid`. One of them must be set which allows you to select something else than rectangle. This is perfectly acceptable answer ;) – TLama Oct 11 '11 at 15:07