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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
{---
j'ai rajouté une 3éme table pour pouvoir bien voir le filtre
PS: on ne peut pas faire un filtre sur une table detail
---}
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, DB, ADODB, StdCtrls, ExtCtrls, DBCtrls;
type
TForm1 = class(TForm)
ComboBox1: TComboBox;
ListBox1: TListBox;
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
DBGrid2: TDBGrid;
ADOTable2: TADOTable;
DataSource2: TDataSource;
ADOTable1ID: TIntegerField;
ADOTable1categuorie: TWideStringField;
ADOTable2idcateguorie: TIntegerField;
ADOTable2Ref: TIntegerField;
ADOTable2libproduit: TWideStringField;
ADOTable3: TADOTable;
ADOTable3idcateguorie: TIntegerField;
ADOTable3Ref: TIntegerField;
ADOTable3libproduit: TWideStringField;
DBNavigator1: TDBNavigator;
procedure FormCreate(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
if combobox1.ItemIndex > -1 then
begin
if ADOTable1.Locate('categuorie', combobox1.Items[combobox1.ItemIndex], []) then
begin
ADOTable3.Filtered := False;
ADOTable3.Filter := 'idcateguorie = ' + ADOTable1.FieldByName('id').AsString;
ADOTable3.Filtered := True;
//********** on alimente le ListBox1 par le champ Litproduit
ListBox1.Clear;
with ADOTable3 do
begin
First;
While Not EOF do
begin
ListBox1.Items.Add(ADOTable3Libproduit.value);
Next;
end;
end;
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ADOTable1.Open;
ADOTable2.Open;
ADOTable3.Open;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
//************** on alimente le comboBox1 par le champ Catégorie
ComboBox1.Clear;
with ADOTable1 do
begin
First;
While Not EOF do
begin
ComboBox1.Items.Add(ADOTable1Categuorie.value);
Next;
end;
end;
ComboBox1.ItemIndex := -1;
end;
end. |
Partager