unit NewDBLookupComboBox;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
DBCtrls, DB;
type
TNewDBLookupComboBox = class(TDBLookupComboBox)
private
FPressed:Boolean;
protected
{ Protected declarations }
procedure Paint; override;
public
{ Public declarations }
published
{ Published declarations }
end;
procedure Register;
implementation
{ TNewDBLookupComboBox }
procedure TNewDBLookupComboBox.Paint;
var
W, X, Flags, FButtonWidth: Integer;
Text: string;
AAlignment: TAlignment;
Selected: Boolean;
R: TRect;
begin
FButtonWidth := GetSystemMetrics(SM_CXVSCROLL);
Canvas.Font := Font;
Canvas.Brush.Color := Color;
Selected := HasFocus and not ListVisible and
not (csPaintCopy in ControlState);
if Selected then
begin
Canvas.Font.Color := clHighlightText;
Canvas.Brush.Color := clHighlight;
end;
if (csPaintCopy in ControlState) and
(ListFields.Count>0) and
(TField(ListFields[0]) <> nil){ and
(Field.Lookup) }then
begin
Text := TField(ListFields[0]).DisplayText;
AAlignment := TField(ListFields[0]).Alignment;
end else
begin
if (csDesigning in ComponentState) and
(ListFields.Count>0) and
(not (TField(ListFields[0]) = nil)) then
Text := Name
else if (ListFields.Count>0) and
(not (TField(ListFields[0]) = nil)) then
Text := TField(ListFields[0]).Text
else
Text := '';
AAlignment := taLeftJustify;
end;
if UseRightToLeftAlignment then ChangeBiDiModeAlignment(AAlignment);
W := ClientWidth - FButtonWidth;
X := 2;
case AAlignment of
taRightJustify: X := W - Canvas.TextWidth(Text) - 3;
taCenter: X := (W - Canvas.TextWidth(Text)) div 2;
end;
SetRect(R, 1, 1, W - 1, ClientHeight - 1);
if (BiDiMode = bdRightToLeft) then
begin
Inc(X, FButtonWidth);
Inc(R.Left, FButtonWidth);
R.Right := ClientWidth;
end;
if SysLocale.MiddleEast then TControlCanvas(Canvas).UpdateTextFlags;
if KeyValue=Null then Text:='';
Canvas.TextRect(R, X, 2, Text);
if Selected then Canvas.DrawFocusRect(R);
SetRect(R, W, 0, ClientWidth, ClientHeight);
if (BiDiMode = bdRightToLeft) then
begin
R.Left := 0;
R.Right:= FButtonWidth;
end;
if not ListActive then
Flags := DFCS_SCROLLCOMBOBOX or DFCS_INACTIVE
else if FPressed then
Flags := DFCS_SCROLLCOMBOBOX or DFCS_FLAT or DFCS_PUSHED
else
Flags := DFCS_SCROLLCOMBOBOX;
DrawFrameControl(Canvas.Handle, R, DFC_SCROLL, Flags);
end;
procedure Register;
begin
RegisterComponents('NoctWolf', [TNewDBLookupComboBox]);
end;
end.
设置
ListField:='name,code';
ListFieldIndex:=1;
这是按照code字段索引查找,并显示name。
分太少!如果只有这么一点分,以后就不回答你的问题了。