我写的,给你参考:
unit XdbComboBox;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, StdCtrls, db, dbctrls,
DBTables, Dialogs, Forms, Graphics;
type
TXdbComboBox = class(TCustomComboBox)
private
{ Private declarations }
NeedUpDataItems : Boolean;
isLoaded : boolean;
FmouseEnter: Boolean;
FDataLink : TFieldDataLink;
FSelColor: Tcolor;
FBlendValue: Byte;
// function GetDataField: String;
GetDataField: string;
function GetDataSource: TDataSource;
procedure SetDataField(Value:String);
procedure SetDataSource(Value:TDataSource);
procedure FSetSelColor(value: TColor);
procedure FSetBlendValue(Value: Byte);
procedure CmMouseEnter(var Msg: TMessage); message CM_MOUSEENTER;
procedure CmMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;
procedure WmPaint(var msg: TMessage); message WM_PAINT;
procedure CMEnter(var Msg: TCMGotFocus); message CM_ENTER;
procedure CmFocusChange(var Msg: TMessage); message CM_FOCUSCHANGED;
protected
{ Protected declarations }
Procedure DataChange(Sender:TObject);
procedure EditingChange(Sender: TObject);
procedure UpdateData(Sender:TObject);
procedure KeyPress(var Key:Char); override;
procedure DrawItem(Index: Integer; Rect: TRect;
State: TOwnerDrawState); override;
procedure DropDown; override;
procedure Click; override;
procedure CreateWnd; override;
procedure CloseUp; override;
public
{ Public declarations }
Constructor Create(AOwner:TComponent); Override;
Destructor Destroy; Override;
procedure UpDataItems;
published
{ Published declarations }
[blue] property SelColor: Tcolor Read FSelColor Write FSetselColor;
property BlendValue: byte Read FBlendvalue write FSetBlendValue;
property DataField : String read GetDataField write SetDataField;
property DataSource: TDataSource read GetDataSource write SetDataSource;[/blue] property AutoComplete default True;
property AutoDropDown default False;
property Style; {Must be published before Items}
property Color;
property Ctl3D;
property DragCursor;
property DragKind;
property DragMode;
property DropDownCount;
property Enabled;
property Font;
property ImeMode;
property ImeName;
property ItemHeight;
property MaxLength;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property Sorted;
property TabOrder;
property TabStop;
property Text;
property Visible;
property OnChange;
property OnClick;
property OnCloseUp;
property OnContextPopup;
property OnDblClick;
property OnDrawItem;
property OnDropDown;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMeasureItem;
property OnSelect;
end;