[Delphi] ListView with Checkboxes!
Hi, can someone help me please, i've a problem with my ListView with checkboxes, i want to delete items that are checked only, how can i do that?!
Forgive me my incorrect English.
Thanks
UltraMAX2K5
Hi, UltraMAX2K5
I think the only why of doing that is to loop through all your items and check whether or not the item is checked.
If it's checked then delete the current index of the items you are looping through and that should be it.
#edit: follow Forfaox code instead that of mine, did't thought about the renumbering.
var Loop: Integer;
for Loop := 0 to ListView1.Items.Count - 1 do begin
if ListView1.Items[Loop].Checked then
ListView1.Items.Delete(Loop);
end;
Hope it helps,
Starik
[Edited by - Starik1974 on January 5, 2005 7:51:25 AM]
I think the only why of doing that is to loop through all your items and check whether or not the item is checked.
If it's checked then delete the current index of the items you are looping through and that should be it.
#edit: follow Forfaox code instead that of mine, did't thought about the renumbering.
var Loop: Integer;
for Loop := 0 to ListView1.Items.Count - 1 do begin
if ListView1.Items[Loop].Checked then
ListView1.Items.Delete(Loop);
end;
Hope it helps,
Starik
[Edited by - Starik1974 on January 5, 2005 7:51:25 AM]
I agree, although Starik's code won't work: When you delete an item, all items following the one deleted will be renumbered, so the posted code may skip deleting some items.
Use either:
or:
Use either:
for i:= ListView1.Items.Count-1 downto 0 do if ListView1.Items.Checked then ListView1.Items.Delete(i);
or:
i:= 0;while i<ListView1.Items.Count do if ListView1.Items.Checked then ListView1.Items.Delete(i) else Inc(i);
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement