TMSFNCDataGrid Sender in CheckBoxChange event wrong?

Add CheckBoc column to grid:

Grid.AddCheckBoxColumn(0,false);

Use change event and check sender:

procedure TForm.GridCellCheckBoxChange(Sender: TObject; AColumn, ARow: Integer);
begin
  ShowMessage(Sender.ClassName);
end;

Sender ist TTMSFNCDataGridRenderer instead of TTMSFNCDataGrid.

Try the same with TTMSFNCGrid and find sender as TTMSFNCGrid - ok.

Hi,

This is by design, the events target the renderer, since the possibility exists for sub-grids and these are all based on the renderer instead. The renderer is the actual grid, the TTMSFNCDataGrid is a wrapper around the renderer. Should you have a need to identify which grid the renderer users, you can use the following code:

function GetGrid(Sender: TObject): TTMSFNCCustomDataGrid;
var
  g: TObject;
begin
  Result := nil;
  if Assigned(Sender) and (Sender is TTMSFNCDataGridRenderer) then
  begin
    g := (Sender as TTMSFNCDataGridRenderer).Host;
    if g is TTMSFNCCustomDataGrid then
      Result := g as TTMSFNCCustomDataGrid;
  end;
end;

procedure TForm13.TMSFNCDataGrid1CellCheckBoxChange(Sender: TObject; AColumn,
  ARow: Integer);
var
  g: TTMSFNCCustomDataGrid;
begin
  g := GetGrid(Sender);
  if Assigned(g) then
  begin
    //...
  end;
end;

I use a method like

procedure DoSomething(Sender:TObject);
begin
  if Sender ist MyButtonName then …
   If Sender is MyGridName then …
end;

What would you suggest to do?

I do not have a MyGridRendererName …

MyGridName, MyButtonName are just class definitions, or how exactly are they defined? TTMSFNCCustomDataGrid is a class definition.

Example: Place two Buttons Name1=myButton1 and Name1=myButton2 on a form.

Both of them have event methods:

procedure Form.myButton1.OnClick(Sender: TObject);
begin
  doSomething(Sender);
end;

procedure Form.myButton2.OnClick(Sender: TObject);
begin
  doSomething(Sender);
end;

The doSomething method identifies the buttons by name:

procedure Form.doSomething(Sender: TObject);
begin
  if Sender=myButton1 then ...

  if Sender=myButton2 then ...
end;

So I need the grid as Sender, because I do not know the name of the renderer behind the grid.

If you assign the OnClick for the button, then the Sender will be the button itself, not the grid. The grid doesn’t have any control over what exactly happens with the control. For built-in controls (column control type for example), there is a separate OnCellButtonClick event. If you want to know the grid, you can check the Parent property of the Sender.

I did not talk about a button on the grid, just a windows button on a form.

The issue is, that I identify the button by name and I wanted to identify your grid by name as well…