PDA

Ver la Versión Completa : aceptar un solo punto en un StringGrid


Narvaez
16-05-2007, 01:05:10
Hola de nuevo, tengo un nuevo problema:
metí el siguiente codigo en un Tedit para que me aceptara numeros reales y un solo punto, me funciona correctamente pero quisiera saber como se le hace para que eso funcione en las celdas de un StringGrid.

Código Delphi [-] (http://www.clubdelphi.com/foros/#)procedure TDatosCultivo.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
If not (Key in ['0'..'9','.',#8]) then Key:=#0;
If (Key='.') and (Pos('.',Edit2.Text)>0) Then Key:=#0;
end;

BuenaOnda
16-05-2007, 06:41:45
Bueno utilizando el codigo que muestras..yo haria lo siguiente..



procedure TForm1.TuGrillaKeyPress(Sender: TObject; var Key: Char);
begin

//Suponiendo que "TuGrilla" posee 4 columnas...
WITH TuGrilla DO
BEGIN
CASE Col OF
1:BEGIN
If not (Key in ['0'..'9','.',#8]) then Key:=#0;
If (Key='.') and (Pos('.',Cells[Col,Row])>0) Then Key:=#0;
END;
2:BEGIN
If not (Key in ['0'..'9','.',#8]) then Key:=#0;
If (Key='.') and (Pos('.',Cells[Col,Row])>0) Then Key:=#0;
END;
3:BEGIN
If not (Key in ['0'..'9','.',#8]) then Key:=#0;
If (Key='.') and (Pos('.',Cells[Col,Row])>0) Then Key:=#0;
END;
4:BEGIN
If not (Key in ['0'..'9','.',#8]) then Key:=#0;
If (Key='.') and (Pos('.',Cells[Col,Row])>0) Then Key:=#0;
END;
END;
END;

end;


espero que te sirva...