TTMSFNCDataGrid - bug when using 2 button columns

Look here:

Two button columns with different images index 0 and 1.

When using the same buttontext ‘x’, the images are also the same in the two grid columns???

procedure TFormTestFNCGrid.FormShow(Sender: TObject);
begin
GridA.AddButtonColumn(0,'x');
GridA.AddButtonColumn(1,'x');
end;

procedure TFormTestFNCGrid.GridAGetCellProperties(Sender: TObject; ACell: TTMSFNCDataGridCell);
begin
if ACell.IsButtonCell then
begin
ACell.AsButtonCell.Button.Images:=VirtualImageList;

if ACell.Column=0
  then ACell.AsButtonCell.Button.ImageIndex:=0;

if ACell.Column=1
  then ACell.AsButtonCell.Button.ImageIndex:=1;

end;
end;

Hi, this is due to cell control caching for performance and speed enabled by default. We are looking into a way of specifying additional control properties to be check when creating image caches. For now, you can workaround it by defining your own cell class

type
  TGlowButtonCell = class(TTMSFNCDataGridButtonCell)
  public
    function SupportsRealControl: Boolean; override;
  end;
...

{ TGlowButtonCell }

function TGlowButtonCell.SupportsRealControl: Boolean;
begin
  Result := True;
end;

procedure TForm13.TMSFNCDataGrid1GetCellClass(Sender: TObject; AColumn,
  ARow: Integer; var ACellClass: TTMSFNCDataGridCellClass);
begin
  ACellClass := TGlowButtonCell;
end;

It does not work even if the button columns in 2 independent grids on the same form do have the same button text…

We are migrating a big number of grids that contain button columns from TMSFNCGrid to TMSFNCDataGrid .

None of these columns has a button text…

It is really important for the migration process, that different grids are completely seperated from each other.

It took me a lot of time to understand the weird situation, that grids share data! That should be clearly documented in the manual.

From a maintenance point of view I am not happy with “workarounds”…

In “the old grid” everything worked pretty well.

I completely understand that this installs more complexity, but the choice was made for performance reasons. We are currently working on events to handle this, where you can switch to real controls via a single line of code. Real controls on the other hand can still be installed via Grid.Controls[Col, Row] although this is a manual process.

I’m providing a workaround in the meantime until the next version is available, where you will be able to do this:

procedure TForm1.TMSFNCDataGrid1GetCellSupportsRealControl(Sender: TObject;
  AColumn, ARow: Integer; AControl: TControl;
  var ASupportsRealControl: Boolean);
begin
  ASupportsRealControl := True;
end;

Enable real controls grid-wide or control which properties are used for the caching mechanism

procedure TForm1.TMSFNCDataGrid1GetCellControlExtraProperties(Sender: TObject;
  AColumn, ARow: Integer; AControl: TControl;
  var AExtraProperties: TArray<System.string>);
begin
  AExtraProperties := ['ImageIndex'];
end;

I’ll make sure to deliver this asap.

Thanks, works fine…

There are similar issues with sorting checkbox columns with no text in cells…

I used “t” and “f” in background color, but that snot a good solution.

You mean caching issues? The new events should counter that.

Not working.

Take a checkbox column and set some rows to checked.

Try to sort column…

After sort I need to have all checked rows on the top of the grid.

Did you apply the sorting technique I mentioned in another post?

Yes I did…

By the way: Why are you putting so many grid definition properties into events? From a maintenance point of view it would be better to have a clear seperation between definition, writing/reading and user events…

About user events: There are important events missing (Key press in edit, click in combobox)

It always has been a way of providing maximum flexibility. At some point we see what’s possible to define grid & column properties without making it cluttered.