Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit1;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls, Grids;
- type
- TCanEditEvent = procedure(Sender: TObject; Col, Row: Longint;
- var CanEdit: Boolean) of object;
- TStringGrid = class(Grids.TStringGrid)
- private
- FOnCanEdit: TCanEditEvent;
- protected
- function CanEditShow: Boolean; override;
- public
- property OnCanEdit: TCanEditEvent read FOnCanEdit write FOnCanEdit;
- end;
- TForm1 = class(TForm)
- StringGrid1: TStringGrid;
- procedure FormCreate(Sender: TObject);
- private
- procedure StringGridCanEdit(Sender: TObject; Col, Row: Longint;
- var CanEdit: Boolean);
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- { TStringGrid }
- function TStringGrid.CanEditShow: Boolean;
- begin
- Result := inherited CanEditShow;
- if Result and Assigned(FOnCanEdit) then
- FOnCanEdit(Self, Col, Row, Result);
- end;
- { TForm1 }
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- StringGrid1.OnCanEdit := StringGridCanEdit;
- end;
- procedure TForm1.StringGridCanEdit(Sender: TObject; Col, Row: Integer;
- var CanEdit: Boolean);
- begin
- // to the CanEdit parameter assign True if you want to allow the cell
- // to be edited, False if you don't
- CanEdit := (Col > 2) and (Row > 2);
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement