Delphi 动态给ComBoBox赋值,从ComBoBox中取值
1、把数据库中的项目信息(项目名称、项目编号)动态赋给ComBoBox
cbProjectName.Items.Clear;
with adoQryProject do
begin
First;
while not Eof do
begin
ProjectNameStr := fieldByName('ProjectName').AsString;
if Trim(ProjectNameStr) <> '' then
cbProjectName.Items.AddObject(ProjectNameStr, TObject(fieldByName('ProjectID').AsInteger));
Next;
end;
end;
2、读取ComBoBox中的值
ProjectID:= IInteger(cbProjectName.Items.Objects[cbProjectName.ItemIndex]);
ProjectName:= cbProjectName.Text;
3、快速定位到某个字段或数据:
1、设置Combobox控件的AutoComplete属性为true即可;
2、combobox1.ItemIndex := Combobox1.Items.IndexOf(trim(edit1.text));