用一个按钮对两个listbox作删除操作,怎么实现?(怎样解决listbox index out of bounds(-1))
谢谢!!!
谢谢!!!
解决方案 »
- ?找Delphi 兼职工作
- delphi中什么控件可以能很好显示office(word,exce)内容的
- 老问题还没解决,请帮我看一下这个SQL语句!
- 各位大侠能否指点一下小弟如何将公历转换成农历?????
- 谁有有关DUnit的文档或下载地址
- 拜师学艺呀!吾乃一介武夫!忽转型!想作文人!!望各位大侠成全!!
- 可用分太多,快7000了,散分
- :(,怎样生成.exe文件
- 各位大虾,救命啊!我在配置bde的时候发现不知道用户名和密码,Access2000的有人知道吗?
- 定时送分!在delphi下用socket编程!
- 在一个表里面添加字段,并赋值,而且该值与已存在的字段有联系,怎么实现
- 现在非典闹的很厉害,不敢出门,有个小问题,请大家帮忙
if (ListBox1.Count=0) and (ListBox2.Count=0) then
MessageDlg('不存在!', mtInformation,[mbOk], 0);
if ((ListBox1.Count>0) or (ListBox2.Count>0)) and ((ListBox1.ItemIndex=-1) and (ListBox2.ItemIndex=-1)) then
MessageDlg('请选择!', mtInformation,[mbOk], 0)
else
begin
if (Listbox1.Selected[listbox1.ItemIndex]) and (Listbox2.Selected[listbox2.ItemIndex]) then
MessageDlg('不能同时选中!', mtInformation,[mbOk], 0)
else if ListBox1.Selected[listbox1.ItemIndex] then
begin
listbox1.Items.Delete(listbox1.itemindex);
listbox1.Update;
listbox1.SetFocus;
end
else
begin
listbox2.Items.Delete(listbox2.itemindex);
listbox2.Update;
listbox2.SetFocus;
end
end
要删除ListBox要注意Items的个数,删了第一个之后,Items.Count已经变了,因此建议这样删
while ListBox.Items.Count > 0 do
begin
//do something...
ListBox.Items.Delete(0);
end;
MessageDlg('不能同时选中!', mtInformation,[mbOk], 0)
else if ListBox1.ItemIndex <> 0 then
ListBox1.Items.Delete(ListBox1.ItemIndex)
else if ListBox2.ItemIndex <> 0 then
ListBox2.Items.Delete(ListBox2.ItemIndex)
else if (ListBox1.Items.Count = 0) and (ListBox2.Items.Count = 0) then
MessageDlg('不存在!', mtInformation,[mbOk], 0)
else MessageDlg('请选择!', mtInformation,[mbOk], 0);
if (ListBox1.ItemIndex <> -1) and (ListBox2.ItemIndex <> -1) then
MessageDlg('不能同时选中!', mtInformation,[mbOk], 0)
else if ListBox1.ItemIndex <> -1 then
ListBox1.Items.Delete(ListBox1.ItemIndex)
else if ListBox2.ItemIndex <> -1 then
ListBox2.Items.Delete(ListBox2.ItemIndex)
else if (ListBox1.Items.Count = 0) and (ListBox2.Items.Count = 0) then
MessageDlg('不存在!', mtInformation,[mbOk], 0)
else MessageDlg('请选择!', mtInformation,[mbOk], 0);