Form1.KeyPreview := True;procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char); begin if (ComboBox1.Text = '电脑配件') and (Ord(Key) = 120) then ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ (ComboBox1.ItemIndex = the index of 电脑配件') // better begin Key := #0; ComboBox2.ItemIndex := 0; end; end;
ComboBox2 的每一项都以你需要的热键字母开头,它的 Style 属性设置为 csDropDownList。然后:procedure TForm1.ComboBox1Select(Sender: TObject); begin ComboBox2.SetFocus; end;
你是不是要的是这种效果呀!!源码如下: procedure TForm1.ComboBox1Change(Sender: TObject); var i:integer; begin i:=combobox1.Items.IndexOf(combobox1.Text); if i>0 then combobox1.AutoDropDown:=true; combobox1.Text:=combobox1.Items[i]; end;
如果KEY=‘X’就让COMBOBOX2。ITEMINDEX:=0;
begin
if (ComboBox1.Text = '电脑配件') and (Ord(Key) = 120) then
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(ComboBox1.ItemIndex = the index of 电脑配件') // better
begin
Key := #0;
ComboBox2.ItemIndex := 0;
end;
end;
begin
ComboBox2.SetFocus;
end;
procedure TForm1.ComboBox1Change(Sender: TObject);
var
i:integer;
begin
i:=combobox1.Items.IndexOf(combobox1.Text);
if i>0 then
combobox1.AutoDropDown:=true;
combobox1.Text:=combobox1.Items[i];
end;