这个问题已经解决的差不多了,在onkeypress事件中写了如下代码,但在过滤时如果第一次
过滤只剩下1个item的话,下拉列表的DropDownCount就成了1,如果back后重新输入,这次
剩下3个item的话,DropDownCount还是1,各位高手有什么办法改变这个值,让它适应item
的个数
procedure TForm1.ComboBox1KeyPress(Sender: TObject; var Key: Char);
var
s,m: string;
i,j: integer;
begin
if key = #13 then begin
showmessage('回车');
exit;
end;
s := ComboBox1.Text;
case Ord(key) of
VK_ESCAPE: begin
ComboBox1.DroppedDown := false;
ComboBox1.Text := s;
exit;
end;
VK_BACK: begin
ComboBox1.Items.LoadFromFile('./aa.txt');
Delete(s,Length(s),1);
for i := 1 to Length(s) do begin
j := 0;
repeat
m := ComboBox1.Items[j];
if (Length(s) <= Length(m)) and (s = m) then
Inc(j)
else
ComboBox1.Items.Delete(j);
until j = ComboBox1.Items.Count;
end;
ComboBox1.Text := s;
for i := 1 to Length(ComboBox1.Text) do
PostMessage(ComboBox1.Handle, WM_KEYDOWN, VK_RIGHT, 1);
exit;
end;
else
s := s + key;
if s = '' then
ComboBox1.Items.LoadFromFile('./aa.txt');
for i := 1 to Length(s) do begin
j := 0;
repeat
m := ComboBox1.Items[j];
if (Length(s) <= Length(m)) and (s = m) then
Inc(j)
else
ComboBox1.Items.Delete(j);
until j = ComboBox1.Items.Count;
end;
ComboBox1.droppedDown := true;
end;
end;