comment ajouter des combobox dans les cellules de stringgrid
j'ai trouvé des codes prêts mais j'ai pas compris comment ça marche
merci
Version imprimable
comment ajouter des combobox dans les cellules de stringgrid
j'ai trouvé des codes prêts mais j'ai pas compris comment ça marche
merci
Dans ce cas tu pourrait poster ce code pour qu'on te l'explique
ok voici le codehttp://www.delphi3000.com/articles/article_3670.asp?SK=
@ Sky88, avec le lien que tu as communiqué, la 1ère unité est celle qui te permet de construire un composant, la seconde, c'est l'utilisation avec ce composant.
Il y a plus simple sans composant spécial :
Au fait, n'oublies pas aussi de fournir la version de Delphi quand tu demandes de l'aide.Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79 unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids; 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); end; var Form1: TForm1; ComboBox1:TComboBox; 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.StringGrid1SelectCell(Sender: TObject;Col,Row: Integer; var CanSelect: Boolean); var R: TRect; begin if (Col > 0) and (Row <> 0) then begin 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; CanSelect := True; end; procedure TForm1.FormShow(Sender: TObject); Var X:Integer; begin StringGrid1.Options:=StringGrid1.Options+[goColSizing,goThumbTracking]-[goEditing]; ComboBox1:=TComboBox.Create(Self); ComboBox1.Parent:=Form1; ComboBox1.Visible:=False; ComboBox1.OnExit:=ComboBox1Exit; ComboBox1.Clear; For X:=1 to 10 do ComboBox1.Items.Add(IntToStr(X)); end; procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin ComboBox1.Free; end; end.
@+,
Cincap
Petite simplification pour le positionnement du Combo.
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 procedure TForm1.StringGrid1SelectCell(Sender: TObject;Col,Row: Integer; var CanSelect: Boolean); var R: TRect; begin if (Col > 0) and (Row <> 0) then begin R := StringGrid1.CellRect(Col, Row); ComboBox1.BoundsRect := R; ComboBox1.Visible := True; if StringGrid1.Cells[Col,Row]<>'' then ComboBox1.Text:=StringGrid1.Cells[Col,Row] else ComboBox1.Text:=''; ComboBox1.SetFocus; end; CanSelect := True; end; procedure TForm1.FormShow(Sender: TObject); Var X:Integer; begin StringGrid1.Options:=StringGrid1.Options+[goColSizing,goThumbTracking]-[goEditing]; ComboBox1:=TComboBox.Create(Self); ComboBox1.Parent:=StringGrid1; ComboBox1.Visible:=False; ComboBox1.OnExit:=ComboBox1Exit; ComboBox1.Clear; For X:=1 to 10 do ComboBox1.Items.Add(IntToStr(X)); end;
@ AndNotOr, bien vu l'ami, ce qui revient au même mais plus simple !
A noter aussi qu'avec D6, Col et Row sont ACol et Arow :
Mon code incrémentait aussi le combobox suivant le nbre de lignesCode:
1
2
3
4
5
6 procedure TForm1.StringGrid2SelectCell(Sender: TObject; ACol,ARow: Integer; var CanSelect: Boolean); var R: TRect; begin .......
@+,
cincap