Board index » delphi » CanSelect odd behavior in tstringgrid

CanSelect odd behavior in tstringgrid

Put a tstringgrid on a form, with options goediting set to true and fixed
columns=0. Leave everything else at the default values.

In the OnSelectCell event place:

CanSelect := Acol = 1;

When you first start the program, you are allowed to edit in column 0, row
1.

Once you edit in any row of column 1 (the desired column),  you will
subsequently be prevented from editing in col 0, row 1.

Is there a work-around to this problem so that the user will be prevented
from editing in column 0, row 1 on at startup?

 

Re:CanSelect odd behavior in tstringgrid


Quote
Bob Richardson wrote:
> Put a tstringgrid on a form, with options goediting set to true and fixed
> columns=0. Leave everything else at the default values.

> In the OnSelectCell event place:

> CanSelect := Acol = 1;

> When you first start the program, you are allowed to edit in column 0, row
> 1.

> Once you edit in any row of column 1 (the desired column),  you will
> subsequently be prevented from editing in col 0, row 1.

> Is there a work-around to this problem so that the user will be prevented
> from editing in column 0, row 1 on at startup?

The default selected column is column zero. Since the grid begins its
life with that column selected, it doesn't call OnSelectCell, so that
column isn't excluded. Apparently, the cell-editing code doesn't ask
permission from the cell-selecting code before doing its stuff.

It seems like there's a simple, straightforward solution: Set the grid
to a valid selection from the start. Set the grid's Col property to 1 in
the form's OnCreate event.

--
Rob

Re:CanSelect odd behavior in tstringgrid


In article <vcjc2vqoafg...@corp.supernews.com>, Rob Kennedy

Quote
<rkenn...@cs.wisc.edu> writes:
>It seems like there's a simple, straightforward solution: Set the grid
>to a valid selection from the start. Set the grid's Col property to 1 in
>the form's OnCreate event.

Or, as more direct and apparent control of editing, in OnSelectCell code ...

  with StringGrid1 do
    if (ACol = 1) then
      Options := Options + [goEditing]
    else
      Options := Options - [goEditing];

It just depends on your GUI design as to whether you really want to stop
selection or stop only editing.

You could also control the _indication_ of selection by writing code in the
OnDrawCell which does not indicate selection for other cells.

Alan Lloyd
alangll...@aol.com

Other Threads