View Issue Details

IDProjectCategoryView StatusLast Update
0023652LazarusLCLpublic2013-01-17 03:10
ReporterIan GoddardAssigned ToJesus Reyes 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version1.0.4Product Build 
Target Version1.2.0Fixed in Version1.1 (SVN) 
Summary0023652: Adding stringgrid row causes onValidate event to fail
DescriptionI have a TStringGrid. I'm using OnValidate to check & reformat some cells.

I also use onSelectCell to check if the last row has been selected and if it has the rowcount is incremented to add another row so that the user always has another row available. When the row is added the OnValidate handler is not called.

The same thing happens if the handler is modified to add another line when the next to row is entered so it's not a side effect of the focus being shifted to the last row.
Additional InformationCode of the onSelectCell handler:

var
  StringGrid : TStringGrid;
begin
  StringGrid := TStringGrid(Sender);

  if aRow = StringGrid.RowCount - 1 then
    StringGrid.RowCount := StringGrid.RowCount + 1;
end;
TagsNo tags attached.
Fixed in Revision39868
LazTarget1.2
WidgetsetGTK 2
Attached Files
  • uExample.pas (1,063 bytes)
    unit uExample;
    
    {$mode objfpc}{$H+}
    
    interface
    
    uses
      Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Grids;
    
    type
    
      { TForm1 }
    
      TForm1 = class(TForm)
        StringGrid1: TStringGrid;
        procedure StringGrid1SelectCell(Sender: TObject; aCol, aRow: Integer;
          var CanSelect: Boolean);
        procedure StringGrid1ValidateEntry(sender: TObject; aCol, aRow: Integer;
          const OldValue: string; var NewValue: String);
      private
        { private declarations }
      public
        { public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.lfm}
    
    { TForm1 }
    
    procedure TForm1.StringGrid1ValidateEntry(sender: TObject; aCol, aRow: Integer;
      const OldValue: string; var NewValue: String);
    begin
      MessageDlg('You called', mtInformation, [mbOK], 0);
    end;
    
    procedure TForm1.StringGrid1SelectCell(Sender: TObject; aCol, aRow: Integer;
      var CanSelect: Boolean);
    var
      StringGrid : TStringGrid;
    begin
      StringGrid := TStringGrid(Sender);
    
      if aRow = StringGrid.RowCount - 1 then
        StringGrid.RowCount := StringGrid.RowCount + 1;
    end;
    
    end.
    
    
    uExample.pas (1,063 bytes)

Relationships

related to 0023660 resolvedBart Broersma TStringGrid option goAutoAddRows has restricted functionality 
related to 0023661 assignedJesus Reyes TStringGrid focus issue 

Activities

Bart Broersma

2013-01-14 21:02

developer   ~0064880

Please add a compilable sample application demonstrating the problem.

Juha Manninen

2013-01-15 10:07

developer   ~0064886

BTW, did you try the "goAutoAddRows" in StringGrid Options property?

2013-01-15 11:51

 

uExample.pas (1,063 bytes)
unit uExample;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Grids;

type

  { TForm1 }

  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    procedure StringGrid1SelectCell(Sender: TObject; aCol, aRow: Integer;
      var CanSelect: Boolean);
    procedure StringGrid1ValidateEntry(sender: TObject; aCol, aRow: Integer;
      const OldValue: string; var NewValue: String);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.StringGrid1ValidateEntry(sender: TObject; aCol, aRow: Integer;
  const OldValue: string; var NewValue: String);
begin
  MessageDlg('You called', mtInformation, [mbOK], 0);
end;

procedure TForm1.StringGrid1SelectCell(Sender: TObject; aCol, aRow: Integer;
  var CanSelect: Boolean);
var
  StringGrid : TStringGrid;
begin
  StringGrid := TStringGrid(Sender);

  if aRow = StringGrid.RowCount - 1 then
    StringGrid.RowCount := StringGrid.RowCount + 1;
end;

end.

uExample.pas (1,063 bytes)

Ian Goddard

2013-01-15 12:30

reporter   ~0064889

In the example code the form is set up with 1 fixed row, 0 fixed columns and rowcount 3. Set goAutoAddRows TRUE.

Set the onValidateEntry event to use the appropriate handler & run the program.

Click on a cell in the top row and then click on the row beneath. The message box will be displayed because the event will have been called on the cell you have just left. The grid will not grow.

Now set the onSelectCell event to use its handler and repeat. When you click on the second row the new row will be added but the message will not be displayed.

Now go back to the Properties and set the goAlwaysShowEditor to True (default is False). This time clicking on the last row adds a row AND shows the message. What's more it does this even if the goAutoAddRows is set to False.

So setting goAlwaysShowEditor allows both events to fire, clearing it causes the SelectCell event to block the the ValidateEntry event. I'm not sure if this is what's supposed to happen.

Also I don't see any effect og goAutoAddRows. What is it supposed to do?

Juha Manninen

2013-01-15 15:26

developer   ~0064894

> Also I don't see any effect og goAutoAddRows. What is it supposed to do?

It lets you go beyond the last row by adding a new one. This was your intention in onSelectCell, right?

Ian Goddard

2013-01-15 18:56

reporter   ~0064897

It seems fairly limited. AFAICS it only adds a row if (a)at least one cell of the bottom row has content and (b) the motion is made with the down arrow. If, for instance I have autoadvance set to aaRightDown and goTab set I can happily tab from one cell to the next & when I get to the end of a line it will wrap to the start of the next line.

Until I get to the end of the last row.

I'd expect it to add another row & focus on the first cell of that row. What happens is that it just stops tabbing and *invisibly* selects the entire cell contents of the last cell. Pressing any character cell then overwrites the cell contents with whatever key was pressed. I don't think this would be counted as user friendly. At the moment I can get by with the onSelectCell and goAlwaysShowEditor. This always allows the tab to work as expected, possibly because there's always another row.

I'd strongly suggest building an example application and letting a few ordinary users play with it and tell you where it departs from what they'd expect to happen.

Juha Manninen

2013-01-15 21:09

developer   ~0064901

Ian: True, the goAutoAddRows behavior clearly need improvements.
Could you please open another issue for it so it will not be forgotten.
A patch would be welcome, too. It should not be very difficult to fix.

I have implemented this goAutoAddRows feature mostly because I needed it for Delphi Converter's settings GUI. However my ToDo list is getting so long that I can't look at this issue right now.

Ian Goddard

2013-01-16 12:01

reporter   ~0064919

Juha, I'll do that. In fact I think it breaks down to a couple of extra issues so I was already thinking of adding issues for both. I understand your situation. I'm not sure I can help with a patch because I've not got into Lazarus/LCL internals. I'm more of an application developer. The intended users for my current application will be non-technical so I need to make sure my interface is as intuitive as possible.

Issue History

Date Modified Username Field Change
2013-01-14 17:34 Ian Goddard New Issue
2013-01-14 17:34 Ian Goddard Widgetset => GTK 2
2013-01-14 21:02 Bart Broersma LazTarget => -
2013-01-14 21:02 Bart Broersma Note Added: 0064880
2013-01-14 21:02 Bart Broersma Status new => feedback
2013-01-15 10:07 Juha Manninen Note Added: 0064886
2013-01-15 11:51 Ian Goddard File Added: uExample.pas
2013-01-15 12:30 Ian Goddard Note Added: 0064889
2013-01-15 15:26 Juha Manninen Note Added: 0064894
2013-01-15 18:56 Ian Goddard Note Added: 0064897
2013-01-15 21:09 Juha Manninen Note Added: 0064901
2013-01-16 12:01 Ian Goddard Note Added: 0064919
2013-01-16 18:48 Juha Manninen Relationship added related to 0023660
2013-01-16 18:49 Juha Manninen Relationship added related to 0023661
2013-01-17 03:06 Jesus Reyes Status feedback => assigned
2013-01-17 03:06 Jesus Reyes Assigned To => Jesus Reyes
2013-01-17 03:09 Jesus Reyes Fixed in Revision => 39868
2013-01-17 03:09 Jesus Reyes LazTarget - => 1.2
2013-01-17 03:09 Jesus Reyes Status assigned => resolved
2013-01-17 03:09 Jesus Reyes Fixed in Version => 1.1 (SVN)
2013-01-17 03:09 Jesus Reyes Resolution open => fixed
2013-01-17 03:10 Jesus Reyes Target Version => 1.2.0