请教如何操作多个checklistbox

chdaner 2009-09-04 11:21:26
我有两个listbox,四个checklistbox控件,checklistbox1和checklistbox3的项目是10个Pass,
checklistbox2和checklistbox4的项目是10个Fail,
listbox1的项目对应checklistbox1和checklistbox2,
listbox2的项目对应checklistbox3和checklistbox4,
即每个listbox项目会有一个状态,pass 或者fail

我的问题是,怎么将listbox1和listbox2的项目和状态都上传到数据库,我只会上传一个listbox的记录,代码如下

procedure TForm1.Button5Click(Sender: TObject); //新增
var
itemindex,i,j:integer;
begin
with adoquery1 do begin
close;
sql.Clear;
sql.Add('select * from T_zdlxfunctest');
open;
append;
for i:=0 to listbox1.Items.Count-1 do begin
itemindex:=i;
edit;
if checklistbox1.Checked[i] then
FieldByName(listbox1.Items.Strings[i]).AsString:=checklistbox1.Items.Strings[i]
else if checklistbox2.Checked[i] then
FieldByName(listbox1.Items.Strings[i]).AsString:=checklistbox2.Items.Strings[i]
else
FieldByName(listbox1.Items.Strings[i]).AsString:='';
post;
end;
end;
...全文
139 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
chdaner 2009-09-07
  • 打赏
  • 举报
回复
OK了,问题已经解决了
haitao 2009-09-06
  • 打赏
  • 举报
回复
贴出界面图片看一看?
2个listbox,怎么和4个checklistbox关联的?
Voidest 2009-09-06
  • 打赏
  • 举报
回复
把Sender as TListBox,然后对这个对象获取数据写入数据库,这样你可以把几个ListBox的Click事件都关联到你写的这个事件上。
如果每个ListBox写入的数据库名称不同,利用ListBox.TAG来区分从而写入不同的数据库。
Frank.WU 2009-09-06
  • 打赏
  • 举报
回复
说实在的,我真的没看懂什么意思
wintergoes 2009-09-04
  • 打赏
  • 举报
回复
再写一个上传listbox2的代码不行
或者把上传listbox数据的代码写成一个公共代码
传入一个tListBox参数
Dision LI 2009-09-04
  • 打赏
  • 举报
回复

for i:=0 to listbox1.Items.Count-1 do begin
itemindex:=i;
edit;
if checklistbox1.Checked[i] then
FieldByName(listbox1.Items.Strings[i]).AsString:=checklistbox1.Items.Strings[i];
if checklistbox2.Checked[i] then
FieldByName(listbox1.Items.Strings[i]).AsString:=checklistbox2.Items.Strings[i];
if not ((checklistbox1.Checked[i]) and (checklistbox2.Checked[i])) then
FieldByName(listbox1.Items.Strings[i]).AsString:='';

bdmh 2009-09-04
  • 打赏
  • 举报
回复
checklistbox无非就是两种状态吗,选中和不选中,你就判断这两种情况,然后写入数据库的状态字段
火龙岛主 2009-09-04
  • 打赏
  • 举报
回复
或许大家没听懂你说什么?
chdaner 2009-09-04
  • 打赏
  • 举报
回复
我写的语句只能将listbox1中的记录上传到服务器,要上传listbox2中的数据到数据库又应该怎么写?我的循环只是在listbox1中进行的,怎么样做能控制listbox2中的数据?

5,392

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧