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
|
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Sockets, StdCtrls;
type
TForm1 = class(TForm)
ComboBox1: TComboBox;
Edit1: TEdit;
Button1: TButton;
procedure ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
procedure ComboBox1DropDown(Sender: TObject);
procedure ComboBox1Select(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
procedure Desactiver(Index:integer);
function TrouverNouvelIndex:integer;
end;
var
Form1: TForm1;
Prev_Index : Integer;
implementation
{$R *.dfm}
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
with (Control as TComboBox).Canvas do
begin
FillRect(Rect);
if Index >= 0 then
begin
if (Control as TComboBox).Items.ValueFromIndex[index]='O'
then font.Color:=clblack else Font.Color:=clDkGray;
TextOut(Rect.Left + 2, Rect.Top, (Control as TComboBox).Items.Names[Index]);
end;
end;
end;
procedure TForm1.ComboBox1DropDown(Sender: TObject);
begin
Prev_Index:=Combobox1.ItemIndex ;
end;
function TForm1.TrouverNouvelIndex:integer;
var i,NewIndex:integer;
begin
with Combobox1 do
begin
If Items.ValueFromIndex[ItemIndex]='N' then
begin
if Items.ValueFromIndex[Prev_Index]='O'
then NewIndex:=Prev_Index
else begin
NewIndex:=-1;
while ((i<Items.count) and (Items.ValueFromIndex[i]='N')) do inc(i);
if i<Items.count then NewIndex:=i;
end;
ItemIndex:=NewIndex;
end;
result:=ItemIndex;
end;
end;
procedure TForm1.ComboBox1Select(Sender: TObject);
begin
TrouverNouvelIndex;
//exemple
Edit1.text:=Combobox1.items.Names[Combobox1.ItemIndex];
end;
procedure TForm1.Activer(Index:integer);
begin
Combobox1.Items.ValueFromIndex[Index]:='O';
end;
procedure TForm1.Desactiver(Index:integer);
begin
Combobox1.Items.ValueFromIndex[Index]:='N';
TrouverNouvelIndex;
//exemple
Edit1.text:=Combobox1.items.Names[Combobox1.ItemIndex];
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Desactiver(ComboBox1.ItemIndex);
end;
end. |
Partager