如何使用Delphi TComboBox自动完成和限制列表 [英] How to both autocomplete and limit to list with Delphi TComboBox

查看:286
本文介绍了如何使用Delphi TComboBox自动完成和限制列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我想从一大堆英国城镇中选择伦敦"

Suppose I want to select 'london' from a big list of UK towns

设置

Combo1.AutoComplete := true;
Combo1.Style := csDropdown;

如果我键入"l",然后键入"o",然后键入"n",则它首先选择以"l"开头的第一项,然后选择以两个字母"lo"开头的第一项,然后选择以开头的第一项"lon".这正是我想要的行为-很好.

if I type 'l' followed by 'o', followed by 'n' it initially selects the first item starting with 'l' and then the first item starting with the two letters 'lo' and then the first starting with 'lon'. This is exactly the behaviour I want - which is good.

但是我也可以输入我喜欢的任何文本,无论它是否在列表中-这很糟糕.

However I can also enter any text I like, whether it's in the list or not - this is bad.

设置

Combo1.AutoComplete := true;
Combo1.Style := csDropdownList;

我无法输入我喜欢的任何文字,只能从列表中选择一个项目-很好.

I can't enter any text I like but only select an item from the list - which is good.

但是现在如果我输入"l",然后输入"o",然后输入"n",则它首先选择以"l"开头的第一项,然后选择以"o"开头的第一项,然后选择以开头的第一项. 'n',而不是全部使用三个字母并选择以'lon'开头的第一项.

But now if I type 'l' followed by 'o', followed by 'n' it initially selects the first item starting with 'l', then selects the first item starting with 'o' and the the first starting with 'n', instead of using all three letters and selecting the first item starting with 'lon'.

我如何一次达到两个目标?

How can I achive both things at once?

ie我想被限制为从列表中选择项目,但也可以开始键入并选择到目前为止我输入的所有字母.

ie I want to be limited to selecting items from the list but also be able to start typing and have it select on all the letters I have typed so far.

推荐答案

使用第二个选项

Combo1.AutoComplete := true;
Combo1.Style := csDropdownList;

并将自动完成延迟从默认值500增加到更大一点,以使用户有时间在自动完成开始之前键入第二个和第三个等字符.

and increase the autocomplete delay from the default 500 to something a little bigger to give the user time to type the second and third etc characters before the autocomplete kicks in.

这篇关于如何使用Delphi TComboBox自动完成和限制列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆