设置 ComboBox1.Style := csDropDownList; 即可。 因为 TComboBox 自带此功能。或者, 若 Sytle := csDropDown; 则在 OnChange 事件中写程序。 // procedure ComboBox1Change(Sender: TObject); var strText: String; intNo, intCount: Integer; begin if Sender is TComboBox then with Sender as TComboBox do begin strText := Text; intCount := Items.Count; intNo := 0; while intNo < intCount do begin if Pos(strText, Items[intNo]) > 0 then begin ItemIndex := intNo; Text := strText; break; end; Inc(intNo) end; end; end;
if combobox1.onenter 才可以
因为 TComboBox 自带此功能。或者, 若 Sytle := csDropDown; 则在 OnChange 事件中写程序。
//
procedure ComboBox1Change(Sender: TObject);
var
strText: String;
intNo, intCount: Integer;
begin
if Sender is TComboBox then
with Sender as TComboBox do
begin
strText := Text;
intCount := Items.Count;
intNo := 0;
while intNo < intCount do
begin
if Pos(strText, Items[intNo]) > 0 then
begin
ItemIndex := intNo;
Text := strText;
break;
end;
Inc(intNo)
end;
end;
end;