View Issue Details

IDProjectCategoryView StatusLast Update
0023173LazarusLCLpublic2016-07-05 15:58
ReporterVojtech CihakAssigned ToJesus Reyes 
Status closedResolutionfixed 
Product Version1.0.3 (SVN)Product Build 
Target Version1.8Fixed in Version1.7 (SVN) 
Summary0023173: Events of TStringGrid
(eventualy AutoAdvance=aaNone;)

Select any cell with keyboard or with mouse.
It generates OnSelection (OK) and OnSelectEditor (but editor is not yet selected !)

Now select editor (on the same cell):
by pressing Enter: no event generated
by mouse click: OnSelectEditor + OnSelection

This is not logical to me.
I would expect:
One OnSelection on select cell and one OnSelectEditor on select editor (regardless if it is with mouse or enter key).

Additional InformationWhen goAlwaysShowEditor=True everything seems correct.

Lazarus r.39145, tested with Qt and GTK2.
TagsNo tags attached.
Fixed in Revision52615
Attached Files


2012-10-20 22:31 (7,707 bytes)

Jesus Reyes

2012-10-21 02:32

developer   ~0063333

Indeed, there is something over there. The logic was that in a grid without editing capabilities, only selection could take place, an advanced grid with editing capabilities should allow to choose a new editor as soon as a change on selection is detected. Under this logic, the current keyboard selection is the right one :).

As it seems, when the AutoEdit property is active (mouse function) actually the grid is making redundant calls to "SelectEditor" and "Selection", as they have already occurred in the first place in order to select the current cell.

I believe this is a workaround, because no events are triggered for initial grid selection (indeed, at start, no selection change has taken place)

I don't know now what to do:
a) Just resolve your report by adding redundant calls on "ENTER"
b) Remove the redundant calls that Mouse AutoEdit is doing.
c) Avoid calling SelectEditor on selection change and do it only when editor is known for sure will be needed.

any option may, to some degree, break existing code

Vojtech Cihak

2012-10-21 11:25

reporter   ~0063341

I vote for c), or at least for b).

@ any option may, to some degree, break existing code

I am also afraid that some changes will break the other people's code.

Vojtech Cihak

2016-07-03 13:16

reporter (2,964 bytes)

Vojtech Cihak

2016-07-03 13:26

reporter   ~0093499

I added a new demo "EnlargeGridClmn" which shows the problem. Due to too many SelectEditor events, columns are getting wider and wider.
If the same demo is compiled with goAlwaysShowEditor in StringGrid1.Options, it works fine.

If there is a risk of breaking backward compatibility caused by removing one redundant OnSelectEditor event, there is another possibility: add public boolean property, field, function or flag which will detect whether the OnSelectEditor will really show the editor or not.

Jesus Reyes

2016-07-04 00:16

developer   ~0093521

The problem here is really we don't know if the editor was activated or not.

In r52615 I introduced a new grid event: OnAfterSelection, this triggers after the editor was possibly activated so in this event you could do something like:

procedure TForm1.StringGrid1AfterSelection(Sender: TObject; aCol, aRow: Integer
  if not StringGrid1.EditorMode then

In your case restoreWidths would be simply:

As a suggestion, you could create a storewidths procedure called at appropiated times, where you do something like this:

procedure TForm1.StoreWidths;
  i: Integer;
  for i:=0 to StringGrid1.Columns.Count-1 do
    StringGrid1.Columns[i].Tag := StringGrid1.Columns[i].Width;

Then restorewidths would be

procedure TForm1.RestoreWidths;
  i: Integer;
  for i:=0 to StringGrid1.Columns.Count-1 do
    StringGrid1.Columns[i].Width := StringGrid1.Columns[i].tag;

This solution should not cause any backward incompatibilities.

Vojtech Cihak

2016-07-05 15:58

reporter   ~0093553

Thanks, it works.

Issue History

Date Modified Username Field Change
2012-10-20 22:31 Vojtech Cihak New Issue
2012-10-20 22:31 Vojtech Cihak File Added:
2012-10-21 01:48 Jesus Reyes Status new => assigned
2012-10-21 01:48 Jesus Reyes Assigned To => Jesus Reyes
2012-10-21 02:32 Jesus Reyes Note Added: 0063333
2012-10-21 11:25 Vojtech Cihak Note Added: 0063341
2016-07-03 13:16 Vojtech Cihak File Added:
2016-07-03 13:26 Vojtech Cihak Note Added: 0093499
2016-07-04 00:16 Jesus Reyes Fixed in Revision => 52615
2016-07-04 00:16 Jesus Reyes LazTarget => 1.8
2016-07-04 00:16 Jesus Reyes Note Added: 0093521
2016-07-04 00:16 Jesus Reyes Status assigned => resolved
2016-07-04 00:16 Jesus Reyes Fixed in Version => 1.7 (SVN)
2016-07-04 00:16 Jesus Reyes Resolution open => fixed
2016-07-04 00:16 Jesus Reyes Target Version => 1.8
2016-07-05 15:58 Vojtech Cihak Note Added: 0093553
2016-07-05 15:58 Vojtech Cihak Status resolved => closed