

dianpu:=ComboBox1.Text; //获取其当前选择的值
ComboBox1.items.strings(ComboBox1.ItemIndex); ;//获取当前选择的项的值
dianpu:=ComboBox1.Items.GetText; //获取其列表中所有值
cbb1.Text:=cbb1.Items.Strings[1]; //获取列表中第2项的值,0为第一项
ComboBox1.Items.Clear; // 清空下拉菜单
// 添加搜索结果
ComboBox1.Items.Add('搜索结果1');
ComboBox1.Items.Add('搜索结果2');
ComboBox1.DroppedDown := True; //设为可展开下拉菜单
ComboBox1.Items := sl; //sl为TStringlist。var sl:TStringList;将TStringlist内容赋值给ComboBox列表
常用属性
Items //设置下拉框每行的内容,类型Memo
ItemIndex //用于设置第几项被选中,或用代码返回被选中的项,默认-1表没有任何被选
CharCase //设置下拉框里的字符全部大写或小写
DropDownCount //下拉框没滚动条时最多显示条数
Sorted //是否给下拉框里的项排序
ItemHeight //用于设置项的高度,只有Style属性为csOwnerDrawFixed或sOwnerDrawVariable时,ItemHeight属性才起作用。
Style //设置下拉框样式,
. csDropDown, 默认,可输出,可下拉
. csDropDownList 只读方式,只能下拉选择,不能输入
. csSimple 相当于一个edit,可输出,可用上下方向箭选择Items中内容
. csOwnerDrawFixed 只读,不能输入,每项高度可在ItemHeight中设置
. csOwnerDrawVariable 在组合框中由一个只读编辑框和列表框组成,条目的高度可以不同。
Items属性有多个子方法和子属性
add 添加一个选项 cbb.items.add('aaa');
Append 功能同上
clear 清空选项
count 获取选项个数
delete 删除指定序号的选项 cbb.items.delete(0) 删除第一个选项
indexof 获取指定内容属性第几个选项,返回值为整形 cbb.items.indexof('aaaa')
Strings 获取指定序号选项的内容,返回字符串 cbb.items.strings(cbb.ItemIndex);
Text 获取选择框中所有内容,类型TstringList中的Text
常用事件
OnChange 当内容改变时,比如选择了其它项或输入了其它内容
OnDragDrop 下拉框打开时
详见:https://blog.csdn.net/yuanstz/article/details/88082167
procedure TMainFr.ComboBox1KeyDown(Sender: TObject; var Key: Word; //当有按键按下时
Shift: TShiftState);
begin
if Key = VK_RETURN then 。。。 //按回车时
if Key = vk_space then 。。。 //按空格时
end;