在您输入TComboBox
时,我试图完成搜索,并在输入时自动添加项目。
我使用Delphi 7和MSSQL。
让我们说我有一个长列表,其中有一个名字列表的表,其中一列名为“ names”,我键入了“ Jonathan”。
我想一一输入,就将结果放入TComboBox
中。
谢谢。
答案 0 :(得分:1)
尝试以下操作:
procedure TForm1.ComboBox1Change(Sender: TObject);
var
I: Integer;
begin
ComboBox1.Items.Clear;
ComboBox1.SelStart:= Length(ComboBox1.Text); //To put the cursor in the end
of the string typed in the ComboBox
if ComboBox1.Text = '' then
ADOTable1.Filtered:= False
else
begin
ADOTable1.Filter:= 'Names LIKE ' + QuotedStr(ComboBox1.Text + '*');
ADOTable1.Filtered:= True;
for I := 1 to ADOTable1.RecordCount do
begin
ADOTable1.RecNo:= I;
ComboBox1.Items.Add(ADOTable1.FieldByName('Names').Value);
end;
end;
end;