我想把combobox改造成以下的样子:还是存入一些原始数据,然后可以在用户输入的时候在combobox的下拉筐里实现原始数据模糊查询的功能,然后让用户选中,各路高人有什么好的建议?
解决方案 »
- 5年不编程的来学delphi的老头子有希望吗?
- Delphi会不会步入VB的后尘,五年以后还会有人用不着delphi了?
- 求一个统计类的SQL语句,想了好半天没有答案了
- 有关程序延时的问题~
- 关于第三方控件DevExpress print system 的问题!!在线等待
- 如何在串口中获得UPS中的各项参数,破产提问,分很多
- delphi 编写activex 如何加载外部dll或bpl
- ★★★★★图象如何进行模糊处理!!★★★★★
- 100分,我在建立表后,每个表都建立一个主键,但每次做关系图都有麻烦
- .NET的含义是什么?包括哪些方面的内容?
- 高手请进,可能是个小问题!
- 请问这个函数怎么用????
S: String;
begin
S := 'abc'
ComboBox1.Perform(LB_FINDSTRING, 1, Integer(S));
end;
unit CompletingComboBox;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TCompletingComboBox = class(TComboBox)
private
FTextCompletion: Boolean;
function GetTextCompletion: Boolean;
procedure SetTextCompletion(const Value: Boolean);
protected
// override the WndProc() so that we can trap KeyUp events.
procedure ComboWndProc(var Message: TMessage; ComboWnd: HWnd;
ComboProc: Pointer); override;
public
{ Public declarations }
published
property TextCompletion: Boolean read GetTextCompletion write SetTextCompletion;
end;procedure Register;implementationprocedure Register;
begin
RegisterComponents('Standard', [TCompletingComboBox]);
end;{ TCompletingComboBox }function TCompletingComboBox.GetTextCompletion: Boolean;
begin
Result := fTextCompletion;
end;procedure TCompletingComboBox.SetTextCompletion(const Value: Boolean);
begin
fTextCompletion := Value;
end;procedure TCompletingComboBox.ComboWndProc(var Message: TMessage; ComboWnd: HWnd;
ComboProc: Pointer);
var
rc, len: Integer;
begin
inherited;
case Message.Msg of
WM_KEYUP:
begin
// test to see if its a character that should not be processed.
if (Message.WParam <> 8) and (Message.WParam <> VK_DELETE) and
(Message.WParam <> VK_SHIFT) and (FTextCompletion = True) then
begin
// Use CB_FINDSTRING to locate the string in the Items property
rc := Perform(CB_FINDSTRING, -1, Integer(PChar(Caption)));
// if its in there then add the new string to the Text and
// select the portion that wasn't typed in by the user
if rc <> CB_ERR then
begin
// store the length of the current string
len := Length(Text); // set the new string
ItemIndex := rc; // highlight the rest of the text that was added.
SelStart := len;
SelLength := Length(Text) - len;
// return 0 to signify that the message has been handled.
Message.Result := 0;
end;
end;
end;
end; // case
end;end.
*************************
Combobox的自动完成
在Combobox的OnChange或者Key事件中,写如下代码,注意,没有处理删除的情况,请自己完成。
procedure TForm1.ComboBox1Change(Sender: TObject);
var
a:integer;
Old:string;
begin
a:=-1;
Old :=ComboBox1.Text;
sendmessage(combobox1.handle,CB_SHOWDROPDOWN,1,0);
a:=SendMessage(ComboBox1.Handle, CB_SELECTSTRING,integer(@a),integer(pchar(ComboBox1.Text)));
ComboBox1.SelStart:=Length(Old);
ComboBox1.SelLength:=Length(ComboBox1.Text)-Length(Old);
ComboBox1.ItemIndex:=a;
end;
***********
unit unit1
....
private
selectitem : boolean;
....procedure TForm1.ComboBox1Change(Sender: TObject);
var
sinput, sselected : string;
i, j : integer;
begin
j := 0;
if not selectitem then
begin
selectitem := true;
exit;
end;
sinput := copy(combobox1.text, 1, combobox1.SelStart);
for i := 0 to combobox1.items.count - 1 do
if copy(combobox1.items[i], 1, length(sinput)) = sinput then
begin
if j = 0 then sselected := combobox1.items[i];
j := j + 1;
end;
if j > 0 then combobox1.Text := sselected
else combobox1.Text := sinput;
combobox1.SelStart := length(sinput);
combobox1.SelLength := length(combobox1.text) - length(sinput);
end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
application.Terminate
end;procedure TForm1.ComboBox1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key = 8 then selectitem := false;
end;procedure TForm1.FormShow(Sender: TObject);
begin
selectitem := true;
end;end.
var
S:string;
findResult:TStrings;
begin
S:= Combobox1.Text;
//调用你的模糊查找程序,找到一些内容
//FindResult:= 你找到的内容
Combobox1.Clear; //清空上次找到的内容
//Combobox1.Items := FindResult; 把你找到的内容放入ComboBox;
//恢复用户输入
Combobox1.Text := S;
Combobox1.SelStart := length(S);
end;
用户输入後按回车、在TlistString内查出数据、放入TCombobox...也可在進入TCombobox時、把TlistString内容全部放入TCombobox、
在OnChange時、查出数据修正TCombobox内容。