unit UEditStrGrd; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids, ComCtrls; type TForm1 = class(TForm) StringGrid1: TStringGrid; procedure StringGrid1SelectCell(Sender: TObject; Col, Row: Integer; var CanSelect: Boolean); procedure FormShow(Sender: TObject); procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); private { Déclarations privées } public { Déclarations publiques } procedure ComboBox1Exit(Sender: TObject); procedure EditCelluleExit(Sender: TObject); procedure FenPluieExit(Sender: TObject); end; var Form1: TForm1; FenPluie: TForm; ComboBox1:TComboBox; EditCellule, EditPluie:TEdit; UpDownPluie : TUpDown; implementation {$R *.dfm} procedure TForm1.ComboBox1Exit(Sender: TObject); begin StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row]:=ComboBox1.Text; ComboBox1.Visible := False; StringGrid1.SetFocus; end; procedure TForm1.EditCelluleExit(Sender: TObject); begin StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row]:=EditCellule.Text; EditCellule.Visible := False; StringGrid1.SetFocus; end; procedure TForm1.FenPluieExit(Sender : TObject); begin StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row]:=EditPluie.Text; FenPluie.ModalResult := mrNone; StringGrid1.SetFocus; end; procedure TForm1.FormShow(Sender: TObject); Var X:Integer; begin // création de la comboBox StringGrid1.Options:=StringGrid1.Options+[goColSizing,goThumbTracking]-[goEditing]; ComboBox1:=TComboBox.Create(Self); ComboBox1.Parent:=Form1; ComboBox1.Visible:=False; ComboBox1.OnExit:=ComboBox1Exit; // Initialisation de la comboBox ComboBox1.Clear; For X:=1 to 10 do ComboBox1.Items.Add(IntToStr(X)); // Création du tEdit EditCellule := TEdit.Create(Self); EditCellule.Parent := Form1; EditCellule.Visible := False; EditCellule.OnExit := EditCelluleExit; // cr&ation de la fenetre pluie FenPluie := TForm.Create(self); With FenPluie do begin Height := Form1.Height div 2; Width := Form1.Width div 3; Left := ((Form1.Width - Width) div 2 )+Form1.Left; Top := ((Form1.Height - Height) div 2 )+ Form1.Top; caption := 'Cumul de pluie'; BorderIcons := [biSystemMenu]; Visible := False; OnExit := FenPluieExit; Parent := Form1; end; // Création des controls de la fenetre de pluie // la zone d'édition EditPluie := TEdit.Create(FenPluie); With EditPluie do begin Parent := FenPluie; Width := 90; ReadOnly := true; Left := ((FenPluie.ClientWidth Div 2) - 10)-45; Top := 30; end; // Le bouton +- UpDownPluie := TUpDown.Create(FenPluie); With UpDownPluie do begin Parent := FenPluie; Left := ((FenPluie.ClientWidth Div 2) - 10) + 60; Top := 10; Width := 30; Height := 60; min := 0; Max := 500; increment := 1; Position := 0; //OnChangingEx := ChangeCumul; futur dévelopement end; end; procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin ComboBox1.Free; EditCellule.Free; FenPluie.Free; EditPluie.Free; UpDownPluie.Free; end; procedure TForm1.StringGrid1SelectCell(Sender: TObject;Col,Row: Integer; var CanSelect: Boolean); var R: TRect; begin if (Col = 10) and (Row <> 0) then begin // initalisation de la comboBox R := StringGrid1.CellRect(Col, Row); R.Left := R.Left + StringGrid1.Left; R.Right := R.Right + StringGrid1.Left; R.Top := R.Top + StringGrid1.Top; R.Bottom := R.Bottom + StringGrid1.Top; ComboBox1.Left := R.Left + 1; ComboBox1.Top := R.Top + 1; ComboBox1.Width := (R.Right + 1) - R.Left; ComboBox1.Height := (R.Bottom + 1) - R.Top; ComboBox1.Visible := True; if StringGrid1.Cells[Col,Row]<>'' then ComboBox1.Text:=StringGrid1.Cells[Col,Row] else ComboBox1.Text:=''; ComboBox1.SetFocus; end; if (Col in [1,2,3,4,5,6,7,9]) and (Row <> 0) then begin // initialisation du TEdit R := StringGrid1.CellRect(Col, Row); R.Left := R.Left + StringGrid1.Left; R.Right := R.Right + StringGrid1.Left; R.Top := R.Top + StringGrid1.Top; R.Bottom := R.Bottom + StringGrid1.Top; EditCellule.Left := R.Left + 1; EditCellule.Top := R.Top + 1; EditCellule.Width := (R.Right + 1) - R.Left; EditCellule.Height := (R.Bottom + 1) - R.Top; EditCellule.Visible := True; if StringGrid1.Cells[Col,Row]<>'' then EditCellule.Text:=StringGrid1.Cells[Col,Row] else EditCellule.Text:=''; EditCellule.SetFocus; end; if (Col =8) and (Row <> 0) then begin // initialisation de la fenetre cumul de pluie if StringGrid1.Cells[Col,Row]<>'' then EditCellule.Text:=StringGrid1.Cells[Col,Row] else EditCellule.Text:=''; FenPluie.ShowModal; end; end; end.