delphi内combobox用法。

2025-02-23 05:19:54
推荐回答(4个)
回答1:

以上事件是一个死循环,所以永远看不到显示的内容;不知道楼上几位回答的时候有没看到?

这段代码应该是放在ComboBox1dropdown事件中;
因为你的ComboBox1.Clear; 和ComboBox1.Items.Add都在触发ComboBox1Change事件,所以程序不出现假死已经算好的了

回答2:

要在combobox 的onchange 事件下面写:
procedure Tfrm_main.ComboBox1Change(Sender: TObject);
begin
ComboBox1.text:='';
with ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('select cno from c');
Open;
if adoquery.recordcount>0 then
begin
while not EOF do
begin
ComboBox1.Items.Add(FieldByName('cno').AsString);
next;
end;
end
else
showmessage('没有相关记录');
exit;
end;

回答3:

1.确定有记录吗?
2.这段代码不要放在ComboBox组件的onChange事件, 放在Button的onClick事件试试
3.也可以这么写
procedure Tfrm_main.ComboBox1Change(Sender: TObject);
begin
ComboBox1.Clear;
ComboBox1.SetFocus;

with ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('select cno from c');
Open;
while not EOF do
begin
ComboBox1.Items.Add(FieldByName('cno').AsString);
next;
end;
end;
end;

回答4:

buttion事件里写

begin
if combobox.text='小明' then edit1.text=100;
if combobox.text='小王' then edit1.text=90;
......
end;

最好是把数据存储到表了。通过查找combobox的值,获取对应的成绩,赋值给edit