一百分求一控件代码

pcwak 2003-11-03 04:37:14
求能进行检索列表的combobox的控件
例如combobox有下面的内容
输入A,在中输入列出AAAA和ADDD
输入B,在中输入列出BBBB和BDDD
输入C,在中输入列出CCCC和CDDD

combobox.Items.Add('AAAA');
combobox.Items.Add('BBBB');
combobox.Items.Add('CCCC');
combobox.Items.Add('ADDD');
combobox.Items.Add('BDDD');
combobox.Items.Add('CDDD');
...全文
38 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
pcwak 2003-11-03
  • 打赏
  • 举报
回复
自己顶
tanqth 2003-11-03
  • 打赏
  • 举报
回复
就用EHLIB
superlionet 2003-11-03
  • 打赏
  • 举报
回复
你所要列出的内容是从数据库中取出来的吗?
如果是那就用模糊查询,把第一个字母相似的查出来然后写到combobox中去就可以了。
kingting 2003-11-03
  • 打赏
  • 举报
回复
TCheckInputEvent = procedure(Sender: TObject; var Valid: Boolean) of object;
TMeasureColorEvent = procedure(Control: TWinControl; Index: Integer;
State: TOwnerDrawState) of object;

// TCustomZtComboBox
TCustomZtComboBox = class(TCustomComboBox)
private
{ Private declarations }
FMaskChar: char;
FValueWidth: longint;
FOldValue: string;
FOnValidate: TCheckInputEvent;
FOnMeasureColor: TMeasureColorEvent;
function GetAsString: string;
function GetAsInteger: longint;
protected
{ Protected declarations }
procedure KeyPress(var Key: Char); override;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure DoEnter; override;
procedure DrawItem(Index: Integer; Rect: TRect;
State: TOwnerDrawState); override;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
function Validate: boolean;
procedure Clear;
procedure Reset;
procedure Locate(NewValue: string);
property AsString: string read GetAsString;
property AsInteger: longint read GetAsInteger;
property MaskChar: char read FMaskChar write FMaskChar;
property ValueWidth: longint read FValueWidth write FValueWidth;
property OnMeasureColor: TMeasureColorEvent read FOnMeasureColor write FOnMeasureColor;
property OnValidate: TCheckInputEvent read FOnValidate write FOnValidate;
end;

// TCustomZtComboBox

function TCustomZtComboBox.GetAsString: string;
var
MaskPos: longint;
begin
MaskPos := Pos(FMaskChar, Text);
if MaskPos = 0 then
result := Text else
result := copy(Text, 1, MaskPos - 1);
end;

function TCustomZtComboBox.GetAsInteger: longint;
begin
result := StrToIntDef(GetAsstring, 0);
end;

procedure TCustomZtComboBox.KeyPress(var Key: Char);
begin
inherited KeyPress(Key);
ztDoEdtKeyPress( Self, Key );
{ if Key = chr(VK_RETURN) then
begin
ZtSelectNext(self, self, true, true);
Key := #0;
end;}
end;

procedure TCustomZtComboBox.KeyDown(var Key: Word; Shift: TShiftState);
begin
if not ztDoEdtKeyDown( Self, Key, Shift ) then
inherited KeyDown(Key, Shift);
{ case Key of
VK_UP:
begin
ZtSelectNext(self, self, false, true);
Key := 0;
end;
VK_DOWN:
begin
ZtSelectNext(self, self, true, true);
Key := 0;
end;
else
inherited KeyDown(Key, Shift);
end;}
end;

procedure TCustomZtComboBox.DoEnter;
//var
// Control: TWinControl;
begin
// Control := ZtFindNextControl(self, nil, true, false, True);
// while (Control <> nil) and (self <> Control) do
// begin
// if not ZtControlValidate(Control) then exit;
// Control := ZtFindNextControl(self, Control, true, false, True);
// end;
ztDoEnter( Self );
inherited DoEnter;
end;

procedure TCustomZtComboBox.DrawItem(Index: Integer; Rect: TRect;
State: TOwnerDrawState);
begin
if (Index < 0) or (Index > Items.Count - 1) then exit;
if assigned(FOnMeasureColor) then FOnMeasureColor(self, Index, State);
Canvas.FillRect(Rect);
Canvas.TextOut(Rect.Left + 2, Rect.Top, GetCol(Items[Index], 0, FMaskChar));
Canvas.TextOut(Rect.Left + FValueWidth, Rect.Top, GetCol(Items[Index], 1, FMaskChar));
end;

function TCustomZtComboBox.Validate: boolean;
begin
result := True;
if (FOldValue <> Text) then
begin
FOldValue := Text;
if assigned(FOnValidate) then FOnValidate(self, result);
if not result then
begin
Reset;
Self.SetFocus;
end;
end;
end;

constructor TCustomZtComboBox.Create(AOwner: TComponent);
begin
inherited create(AOwner);
FMaskChar := '|';
FValueWidth := 20;
Style := csOwnerDrawFixed;
Reset;
end;

procedure TCustomZtComboBox.Clear;
begin
Reset;
inherited Clear;
end;

procedure TCustomZtComboBox.Reset;
begin
FOldValue := #13#10;
end;

procedure TCustomZtComboBox.Locate(NewValue: string);
var
Index, iTemp: longint;
begin
iTemp := -1;
for Index := 0 to Items.Count - 1 do
if NewValue = GetCol(Items[Index], 0, FMaskChar) then
begin
iTemp := Index;
break;
end;
ItemIndex := iTemp;
end;

// TZtComboBox
TZtComboBox = class(TCustomZtComboBox)
published
property Style; //Must be published before Items
property Color;
property Ctl3D;
property DragMode;
property DragCursor;
property DropDownCount;
property Enabled;
property Font;
property ImeMode;
property ImeName;
property ItemHeight;
property Items;
property MaskChar;
property MaxLength;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property Sorted;
property TabOrder;
property TabStop;
property Text;
property ValueWidth;
property Visible;
property OnChange;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnDrawItem;
property OnDropDown;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMeasureItem;
property OnMeasureColor;
property OnStartDrag;
property OnValidate;
end;

5,387

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧