输入TComboBox csDropDownList;德尔福10

时间:2017-06-14 13:58:15

标签: delphi tcombobox

强制用户从下拉列表中进行选择时 我将组合框的样式设置为csDropDownlist。 enter image description here

但是,此后所有打字只是一个字符。 这意味着,用户无法通过键入多个字符来缩小组合中的搜索范围。那么没用。

将样式设置为csDropDown时,您可以键入多个字符以缩小搜索范围, enter image description here

然后你不再被迫从列表中选择

enter image description here

有没有办法将这些行为结合起来?

1 个答案:

答案 0 :(得分:0)

感谢您的所有投入。

我在这里找到了一个解决方法: How to both autocomplete and limit to list with Delphi TComboBox 我修改了一下:

procedure TForm1.ComboBox1KeyPress(Sender: TObject; var Key: Char);
var
 s, t: string;
i, l: Integer;
const CrLf = #13#10;
begin
 // Skip functional keys
 if Key < ' ' then
  Exit;

  key := upcase(key);

  // Get text which can be in the combo after key pressed
  i := ComboBox1.SelStart;
  l := ComboBox1.SelLength;
  t := ComboBox1.Text;
  s := Copy(t, 1, i) + Key;

  // Check is this text corresponds to the values list

  if pos(CrLf+s, CrLf+combobox1.Items.Text) > 0 then
  exit;


  Key := #0;
end;

现在它完全符合预期,但我尚未测试过长项列表。

但是谢谢所有人。