Evento no String Grid
30/01/2006
0
Exemplo: Estou na Celula(1,1) é vou clicar na Célula(2,1) , na hora que clicar na Célula(2,1) quero chamar uma função que recebe como parametro as informações da Célula(1,1).
OBS: Nem sempre a troca de célula é de uma logo após a outra, ou seja, as vezes posso sair da Celula(1,1) para a Célula (5,2).
Obrigado.
Mascotepc
Posts
30/01/2006
Michael
Infelizmente a classe [b:d1fcad19a4]TStringGrid [/b:d1fcad19a4]não provê nenhum evento que atenda às suas necessidades. Porém, é extremamente simples extender o componente, adicionando um gatilho para a situação desejada. Veja um esboço:
type TOnCellExitEvent = procedure(Sender: TObject; ACol, ARow: Integer; var CanExit: Boolean) of object; TExtStringGrid = class(TStringGrid) private FOnCellExit: TOnCellExitEvent; FLastCol, FLastRow: LongInt; protected function SelectCell(ACol, ARow: Longint): Boolean; override; public constructor Create(AOwner: TComponent); override; published property OnCellExit: TOnCellExitEvent read FOnCellExit write FOnCellExit; end; implementation constructor TExStringGrid.Create(AOwner: TComponent); begin inherited; FLastCol := -1; FLastRow := -1; end; function TExStringGrid.SelectCell(ACol, ARow: LongInt): Boolean; var CanExit: Boolean; begin if (FLastCol = -1) and (FLastRow = -1) then begin FLastCol := ACol; FLastRow := ARow; inherited; end else begin CanExit := True; if Assigned(FOnCellExit) then FOnCellExit(Self, FLastCol, FLastRow, CanExit); if CanExit then inherited; end; end;
O esboço acabou virando a arte final... ;-)
Não testei esse código, portanto não posso garantir que vai funcionar de primeira.
[]´s
30/01/2006
Mascotepc
31/01/2006
Mascotepc
Clique aqui para fazer login e interagir na Comunidade :)