我希望实现Combox中联想输入的功能,combox的输入项目在数据库中保存;
当combox输入时,自动下拉,动态列出item项目,请给方法或者给可以这样实现的控件!
确实可行马上给分;比如:
combox.items.add('测试1');
combox.items.add('测试2');
combox.items.add('测试3');
combox.items.add('test1');
combox.items.add('test2');
当我在combox.text输入:测试
combox的item只列出:
combox.items.add('测试1');
combox.items.add('测试2');
combox.items.add('测试3');
当combox输入时,自动下拉,动态列出item项目,请给方法或者给可以这样实现的控件!
确实可行马上给分;比如:
combox.items.add('测试1');
combox.items.add('测试2');
combox.items.add('测试3');
combox.items.add('test1');
combox.items.add('test2');
当我在combox.text输入:测试
combox的item只列出:
combox.items.add('测试1');
combox.items.add('测试2');
combox.items.add('测试3');
解决方案 »
- 在Form2中调用Form1中的Button的OnClick事件为什么不执行?
- 如何读取和修改网络上的文本文件
- UDP通讯与SOCKET通讯有什么区别啊???
- delphi爱好者的群欢迎大家的加入!!!群号3975439
- 谁知道那里可以下载 整理DELPHI7源代码的工具?送30分
- 请问,怎样把TImageList的图片赋值给TBitBtn.Glyph属性
- 关于listview按照某一列进行排序的问题
- PageControl控件没有鼠标双击事件?
- 请问大虾:排课算法哪儿找?
- 以下程序代码若用delphi写应如何:(这是c)
- 急求一个SQL查询?不知是否有这种可能SQL语句?感谢
- 有管Delphi中时间的问题.
procedure TForm1.ComboBox1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
vSql, vInput: string;
begin
vInput := ComboBox1.Text;
vSql := 'select departName from vo_department where departName like ''%'+ vInput +'%''';
Memo1.Lines.Add(vSql);
with ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add(vSql);
Open;
First;
ComboBox1.Items.Clear;
while not Eof do
begin
ComboBox1.Items.Add(fieldbyName('departname').AsString);
Next;
end;
end;
ComboBox1.AutoDropDown := True;
ComboBox1.AutoComplete := True;
ComboBox1.SelStart:=Length(vInput);
end;
var
i:integer;
begin
ComboBox1.Items.Add('测试1');
ComboBox1.Items.Add('测试2');
ComboBox1.Items.Add('测试3');
ComboBox1.Items.Add('测试4');
ComboBox1.Items.Add('123');
ComboBox1.Items.Add('456');
ComboBox1.Items.Add('vag1');
ComboBox1.Items.Add('vag');
ComboBox1.Items.Add('vag2');
ComboBox1.Items.Add('vag3');
//把列表保存在TStringList里面
for i:=0 to ComboBox1.Items.Count-1 do str.Add(ComboBox1.Items.Strings[i]);end;procedure TForm1.ComboBox1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
i,count:Integer;
text:String;
begin
text:=ComboBox1.Text;//保存输入的文本
count:=Length(ComboBox1.Text);// 保存长度 ComboBox1.Clear; //清除列表 //加载新的列表
for i:=0 to str.Count-1 do
begin
if LeftStr(str.Strings[i],count)=text then
ComboBox1.Items.Add(str.Strings[i]);
end;
ComboBox1.AutoDropDown:=true;
ComboBox1.AutoComplete:=true;
ComboBox1.Text:=text;//复原输入的文本
ComboBox1.SelStart:=count;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
str:=TStringList.Create;
end;