View Issue Details
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0023173||Lazarus||LCL||public||2012-10-20 22:31||2016-07-05 15:58|
|Reporter||Vojtech Cihak||Assigned To||Jesus Reyes|
|Product Version||1.0.3 (SVN)||Product Build|
|Target Version||1.8||Fixed in Version||1.7 (SVN)|
|Summary||0023173: Events of TStringGrid|
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 Information||When goAlwaysShowEditor=True everything seems correct.|
Lazarus r.39145, tested with Qt and GTK2.
|Tags||No tags attached.|
|Fixed in Revision||52615|
GridSelectEditor.zip (7,707 bytes)
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
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.
EnlargeGridClmn.zip (2,964 bytes)
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.
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:
for i:=0 to StringGrid1.Columns.Count-1 do
StringGrid1.Columns[i].Tag := StringGrid1.Columns[i].Width;
Then restorewidths would be
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.
||Thanks, it works.|
|2012-10-20 22:31||Vojtech Cihak||New Issue|
|2012-10-20 22:31||Vojtech Cihak||File Added: GridSelectEditor.zip|
|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: EnlargeGridClmn.zip|
|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|