Advertisement
TLama

Untitled

Feb 28th, 2014
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.37 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, StdCtrls, Grids;
  8.  
  9. type
  10.   TCanEditEvent = procedure(Sender: TObject; Col, Row: Longint;
  11.     var CanEdit: Boolean) of object;
  12.  
  13.   TStringGrid = class(Grids.TStringGrid)
  14.   private
  15.     FOnCanEdit: TCanEditEvent;
  16.   protected
  17.     function CanEditShow: Boolean; override;
  18.   public
  19.     property OnCanEdit: TCanEditEvent read FOnCanEdit write FOnCanEdit;
  20.   end;
  21.  
  22.   TForm1 = class(TForm)
  23.     StringGrid1: TStringGrid;
  24.     procedure FormCreate(Sender: TObject);
  25.   private
  26.     procedure StringGridCanEdit(Sender: TObject; Col, Row: Longint;
  27.       var CanEdit: Boolean);
  28.   public
  29.     { Public declarations }
  30.   end;
  31.  
  32. var
  33.   Form1: TForm1;
  34.  
  35. implementation
  36.  
  37. {$R *.dfm}
  38.  
  39. { TStringGrid }
  40.  
  41. function TStringGrid.CanEditShow: Boolean;
  42. begin
  43.   Result := inherited CanEditShow;
  44.  
  45.   if Result and Assigned(FOnCanEdit) then
  46.     FOnCanEdit(Self, Col, Row, Result);
  47. end;
  48.  
  49. { TForm1 }
  50.  
  51. procedure TForm1.FormCreate(Sender: TObject);
  52. begin
  53.   StringGrid1.OnCanEdit := StringGridCanEdit;
  54. end;
  55.  
  56. procedure TForm1.StringGridCanEdit(Sender: TObject; Col, Row: Integer;
  57.   var CanEdit: Boolean);
  58. begin
  59.   // to the CanEdit parameter assign True if you want to allow the cell
  60.   // to be edited, False if you don't
  61.   CanEdit := (Col > 2) and (Row > 2);
  62. end;
  63.  
  64. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement