delphi - 输入时如何填充 ComboBox?
问题描述
我正在尝试在您输入 a 时完成搜索,TComboBox
并在我输入时自动添加项目。
我使用 Delphi 7 和 MSSQL。
假设我有一个长表,其中包含一列名为“名称”的表中的名称列表,我输入了“乔纳森”。
我想在TComboBox
我一一键入时将结果输入。
谢谢。
解决方案
尝试以下操作:
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;