var
MyTEXT : String;
ed: TInplaceEdit;
MyValue : Integer;
begin
MyTEXT:=REVISION_LISTBOX.Cells[MyCOL,MyROW];
ed:= GetInPlaceEdit(REVISION_LISTBOX);
if ed <> nil then
begin
case ed.SelStart of
//mois
0 :
begin
case StrToIntDef(MyTEXT[2], 0) of
0..2 : if not (key in ['0','1']) then key:=#0;
3..9 : if not (key = '0') then key:=#0;
-1 : if not (key in ['0'..'9']) then key:=#0;
end;
end;
1 :
begin
case StrToIntDef(MyTEXT[1], 0) of
0 : if not (key in ['0'..'9']) then key:=#0;
1 : if not (key in ['0'..'2']) then key:=#0;
-1 : if not (key in ['0'..'9']) then key:=#0;
end;
end;
//jour
3 :
begin
case StrToIntDef(MyTEXT[5], 0) of
0..1 : if not (key in ['0'..'3']) then key:=#0;
2..9 : if not (key in ['0'..'2']) then key:=#0;
-1 : if not (key in ['0'..'3']) then key:=#0;
end;
end;
4 :
begin
case StrToIntDef(MyTEXT[4], 0) of
0..2 : if not (key in ['0'..'9']) then key:=#0;
3 : if not (key in ['0'..'1']) then key:=#0;
-1 : if not (key in ['0'..'9']) then key:=#0;
end;
end;
//annee
7 : key:='0';
end;
end;
end;
Value:='99/99/2099'; // mois/jour/année), j'ai l'affichage suivant dans la cellule :"__/__/2___" au lieu de "__/__/20__" ? "
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs
, GRIDs // TStringGrid
, ComCtrls // TDateTimePicker
;
type
TForm1 = class(TForm)
MyGRID: TStringGrid;
DateTimePicker: TDateTimePicker;
procedure MyGRIDDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect;
State: TGridDrawState);
procedure DateTimePickerExit(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure MyGRIDSelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
MyCOL, MyROW : Integer;
implementation
{$R *.dfm}
procedure TForm1.DateTimePickerExit(Sender: TObject);
begin
MyGRID.Cells[MyCOL, MyROW]:=FormatDateTime('mm/dd/yyyy', DateTimePicker.Date);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
DateTimePicker.Date:=Now;
end;
procedure TForm1.MyGRIDDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
txt : string;
I : Integer;
begin
With Sender As TStringGrid Do With Canvas Do
Begin
DateTimePicker.Visible:=False;
if (ACol <> 0) then
begin
FillRect(rect);
end else
begin
if (gdFocused in State) then
begin
with DateTimePicker do
begin
Left := Rect.Left + MyGRID.Left + 1;
Top := Rect.Top + MyGRID.Top + 1;
Width := Rect.Right - Rect.Left + 2;
Width := Rect.Right - Rect.Left + 2;
Height := Rect.Bottom - Rect.Top + 2;
Visible := True;
end;
MyCOL:=ACol;
MyROW:=ARow;
end;
FillRect(rect);
End;
DrawText(Canvas.Handle,PChar(Cells[ACol,ARow]),-1,Rect,DT_CENTER or DT_NOPREFIX or DT_VCENTER or DT_SINGLELINE );
end;
end;
procedure TForm1.MyGRIDSelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
begin
if (ACol <> 0) then DateTimePicker.Visible:=False
else DateTimePicker.Visible:=True;
end;
end.
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.