delphi如何向combobox的items里添加内容?

delphi如何向combobox的items里添加内容?,第1张

从问题描述来看,推测可能是 ComboBox 的动态设置问题。

示例代码如下:

procedure TForm1.Button1Click(Sender: TObject)

begin

  ComboBox1.Clear

  ComboBox1.Items.Add('标题1')

  ComboBox1.Items.Add('标题2')

end

运行截图:

//只会添加数据库中的用户表

procedure TForm1.Button1Click(Sender: TObject)

begin

with ADOQuery1 do

begin

Close

SQL.Text := 'use 数据库名 select name from sysobjects where xtype=''u'' and status>=0'

Open

while not Eof do

begin

Combobox1.Items.Add(FieldByName('name').AsString)

Next

end

Combobox1.ItemIndex := 0

end

end

1、一次添加完

combobox1.items.AddStrings(listbox1.Items)

2、添加选中的项到combobox

if listbox1.ItemIndex >-1 then //判断listbox1是否有选中的项

combobox1.items.add(listbox1.Items[listbox1.ItemIndex])


欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/bake/11314782.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-15
下一篇 2023-05-15

发表评论

登录后才能评论

评论列表(0条)

保存