读书人

combobox的有关问题大家是如何解决的

发布时间: 2012-03-13 11:21:11 作者: rapoo

combobox的问题,大家是怎么解决的哈

Delphi(Pascal) code
with datamodule1.qdepartment do    begin        close;        sql.clear;        sql.add('select * from department order by departmentid');        open;    end;    while not datamodule1.qdepartment.eof do    begin        combobox4.items.Add(datamodule1.qdepartment.fieldbyname('departmentname').Value);        datamodule1.qdepartment.Next; //数据后移    end;


我通过如上代码将department表中的部门名循环添加到combobox4中..

在一个信息录入窗口中,我通过选取combobox中的部门名,怎么将该部门名岁对应的部门号插入到一个表(该表含有部门号字段,即部门号字段为该表的外键)中呢?...

//不要再告诉我又循环娶出来做比较然后再确定部门号啊,那太晕了哈..



department table: (departmentid,departmentname,remark)

[解决办法]
combobox4.items.AddObject(datamodule1.qdepartment.fieldbyname('departmentname').Value,TObject(编号));
用AddObject添加

Integer(combobox4.Items.Objects[combobox4.ItemIndex]
这个是得到编号

读书人网 >.NET

热点推荐