JustForNous
Messages postés4Date d'inscriptionmardi 26 octobre 2004StatutMembreDernière intervention19 octobre 2005 15 oct. 2005 à 10:25
Merci DrJerome
J'ai modifié légèrement ta réponse pour prendre en compte la touche BackSpace qui doit pouvoir fonctionner même si la longueur est atteinte. De plus la gestion de Stop doit se faire entièrement dans StringGrid1KeyPress pour fonctionner correctement. Ce qui donne :
procedure TForm1.StringGrid1SetEditText(Sender: TObject; ACol, ARow: Integer; const Value: string);
begin
Stop:(ACol 2) and (Length(Value) >= 3)
end;
procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char);
begin
if Stop and (Ord(Key) <> 8) then Key := chr(0);
end;
DRJEROME
Messages postés436Date d'inscriptionjeudi 9 janvier 2003StatutMembreDernière intervention 5 février 2015 15 oct. 2005 à 08:38
<HR>
var
Form1: TForm1;
Stop:boolean;
implementation
{$R *.DFM}
procedure TForm1.StringGrid1SetEditText(Sender: TObject; ACol,
ARow: Integer; const Value: String);
begin
if (ACol=2) and (Length(Value)=3) then Stop:=true;
end;
procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char);
begin
if Stop then Key:=chr(0);
end;
procedure TForm1.StringGrid1Click(Sender: TObject);
begin
Stop:=false;
end;
<HR>
dans cet exemple si la colonne est la n°2 on ne peut rentrer au-delà de 3 caractères
(il y a certainement d'autres solutions)
Transforme le code à ta guise
N'oubliez pas de cliquer sur Réponse acceptée si c'est OK