AdvStringGrid check box and change cell

Good morning to all,
i have a grid with 5 columns; The first one is a checkbox (unchecked) and the last one is a text cell.
The "rule" is that is possible change the chackbox state only if the column 5 has some text, if not i need to change the column from 1 to 5 and swith in edit mode.
Even this is an "easy" matter, reach it is not, really, an easy matter (till now).
With all my work i'm not able to change the column !!!
Grid setting, Option as defaut with GoRowSelect:=True in order to move the coursor on all row.
When click on chceckbox i check if it's possible change the state with

CheckBoxCanToggle(Sender: TObject; ACol, ARow: Integer; State: Boolean; var Allow: Boolean);

Here i have the Row index and check if the last column has some text, if not i can't change the state and switch in edit mode on column 5 with

procedure TFSSMS.SG1CheckBoxCanToggle(Sender: TObject; ACol, ARow: Integer;
  State: Boolean; var Allow: Boolean);
begin
  if SG1.Cells[5,ARow]='' then 
  begin
    SG1.Options:=SG1.Options - [goRowSelect];
    Sg1.Col:=5; // ACol=1 because the checkbox is in this column
    Allow:=False; // Can't chnge the checkbox state ...
  end;
end;

When the program start the grid coordinate are Col=1 and Row=1.
If i click on col=1 (checkBox) and Row=3 what happend is (according to the above code) the grid switch from gorowselect to goEdit and the cell in column 5 is highlated but on the wrong row, the row still remain 1 even ARow is 3.

I tried with the other CheckBox and CanClickCell events without any result.
Is possible reach this kind of work ?

Thank's for attention

Regards

Daniele

Hi to all,
some news ..... the columns now are 4 (but this is not so important ..)

here the events i use

procedure TFSSMS.SG1CanClickCell(Sender: TObject; ARow, ACol: Integer;
  var Allow: Boolean);
begin
  Allow:=False;
  if ACol=4 then
  begin
    SG1.Options:=SG1.Options - [goRowSelect];
    SG1.EditCell(4,Arow);
    Allow:=True;
  end
  else
  if ACol=1 then Allow:=True;
end;
procedure TFSSMS.SG1CellChanging(Sender: TObject; OldRow, OldCol, NewRow,
  NewCol: Integer; var Allow: Boolean);
begin
  if OldCol=4 then
  begin
    SG1.Options:=SG1.Options + [goRowSelect];
    SG1.Col:=1;
    Allow:=False;
  end;
end;
procedure TFSSMS.SG1CheckBoxCanToggle(Sender: TObject; ACol, ARow: Integer;
  State: Boolean; var Allow: Boolean);
begin
  if SG1.Cells[4,ARow]='' then
  begin
    Allow:=False;
    if (not (goRowSelect in SG1.Options)) then  SG1.Options:=SG1.Options + [goRowSelect];
    SG1.Row:=ARow;
    SG1.Col:=4;
    SG1.Options:=SG1.Options - [goRowSelect];
    SG1.EditCell(4,Arow);
  end;
end;

When the form is showed the grid is on row=1, col=1 and gorowselect is in option.
Now click in column 4 in any row, all as expected with the code the selected cell in column 4 in row x is in edit mode.
Now try to click on any checkbox, as before all as expected ... the new cell, always in column4, in a new row is in edit mode ..
Now with cursor key move up/down or click in any other cells in the same column (4), the grid perform SG1CellChanging event, gorowselect is in option and the new row is full highlated.
In this condition, click on any checkbox; The SG1CheckBoxCanToggle is fired and the grid is blocked (freeze).
The same happend at the very first click on any checkbox when the form is showed.

Strange bheaviour ... or, simply, maybe this can't be done,

Excuse me if i do not enougth clear .... and for this long post ..

Regards

Daniele

I suspect you use goRowSelect just to make a row visually appear as selected.
goRowSelect applies the entire row is in selected state, hence, not a single cell is selected and a single cell needs to be selected before it can enter in editing state.
As an alternative, you might consider grid.ActiveRowShow = true instead of goRowSelect in Options.
That should make this easier to handle as you never need to toggle between goRowSelect and not to start or not start the inplace editing.

Good morning Bruno,
about your suspect .... you have rigth !!!
I use it just for "cosmetic purpose" when the grid must not edit any cell.
The rigth way is, as you suggest, use grid.ActiveRowShow = true.
In this way the active row is full show with ActiveRowColor with the exception of the current cell; In this situation using the left or rigth row key the ActiveCell is moving because visible with a different color.
Which is the option to hide the ActiveCell when the ActiveRowShow is true (i'm sure there's one).

Thank's for your help

Regard
Daniele

What exactly you expect from "hiding active cell"? Not show the focus border? If so, set grid.ShowFocus = false.
If you refer to color, make sure ActiveRowColor and SelectionColor are the same.

Hi Bruino,
thank's for reply...

This grid.ShowSelection = false do the job ... but a dot rectangle still remail in a focused cell ....

Thank's

Daniele

grid.ShowFocus = false.

Hi Bruno,
excuse me ... with last version of TMS UI library, i do not see ShowFocus in TAdvStringGrid.
Is it in a subgroup? (like options or similar?).

Thank's for all

Have a nice week end..

Daniele

Sorry, I confused with another control.
The property is grid.HideFocusRect = true

Thank's Bruno ..