简体   繁体   中英

Create readonly text column TGrid firemonkey

I created my custom Column classes from TColumn and i am doing some custom drawing on cell canvas like this:

type
  TCustomCol = class(TColumn)
  protected
    procedure DrawCell(const Canvas: TCanvas; const Row: integer; const Bounds: TRectF; const Value: TValue); override;
  end;

The problem is that my cells are all editable by default, if i dont set editing mode in grid options they will be non editable but i want only certain cells to be non-editable.

You can override protected TCustomGrid.CanEdit function in your unit, before declaring of TForm/TFrame:

type
  TGrid = class(FMX.Grid.TGrid)
  protected
    function CanEdit: Boolean; override;
  end;

  TmyForm = class(TForm)
    myGrid: TGrid;
  .....
  end;
implementation
....
function TGrid.CanEdit: Boolean;
begin
  Result := inherited CanEdit and not ((ColumnIndex = 0) and (Selected < 2)); //use your condition
end;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM