小的对ListBox不是很了解,在做程序是遇到了些难题:
1,如何通过按钮实现对ListBox的内容的全选?(假如:ListBox中的内容是标题,一行一行的)
2,在ListBox1中显示的内容选入ListBox2后,如何将该内容在ListBox1中去掉。(假如:ListBox中的内容是标题,一行一行的)
请教各位大虾!
1,如何通过按钮实现对ListBox的内容的全选?(假如:ListBox中的内容是标题,一行一行的)
2,在ListBox1中显示的内容选入ListBox2后,如何将该内容在ListBox1中去掉。(假如:ListBox中的内容是标题,一行一行的)
请教各位大虾!
2)listbox1.items.delete(listbox1.itemindex);...是不是?我这里没有delphi,不能帮你写了
listbox1.SelectAll;
(2)listbox2.Items.AddStrings(listbox1.Items);
listbox1.Items.Clear;
listbox2.Items.Add(listbox1.Items.Strings[listbox1.ItemIndex]);
listbox1.DeleteSelected;
谢谢两位大虾。!!!
对于第一个问题,如果我想再进一步来实现,如:我全选后,再往ListBox2中添加的话如何实现:
我的实现是这样的:
var
i:Integer;
For i:=0 to ListBox1.Items.Count-1 do
begin
if ListBox1.Selected[i] then
begin
ListBox2.Items.Add(ListBox1.Items.Strings[ListBox1.ItemIndex]);
ListBox1.DeleteSelected;
end;
end;
不过,调试的时候还是有问题:Project Project1.exe raised exception class EListError with message"List index out of bounds(112)",Process stopped.
请教:是不是我的For语句用得不对,我觉得提示得意思应该是越出他得查找范围了。应该怎写才对?
i:Integer;
begin
For i:=0 to ListBox1.Items.Count-1 do
ListBox2.Items.Add(ListBox1.Items.Strings[i]);
listbox1.Clear;
end;
i:Integer;
begin
For i:=0 to ListBox1.Items.Count-1 do
ListBox2.Items.Add(ListBox1.Items.Strings[i]);
listbox1.SelectAll;
listbox1.DeleteSelected;
end;
listbox1.Clear;
------------------------------------------------------
这样最好吧!
begin
if ListBox1.Selected[i] then
begin
ListBox2.Items.Add(ListBox1.Items.Strings[i]);
end;
end;
ListBox1.DeleteSelected;
listbox1.SelectAll;
(2)
listbox2.Items.Add(listbox1.Items.Strings[listbox1.ItemIndex]);
listbox1.DeleteSelected;