• Advertisement
Sign in to follow this  

[Delphi] ListView with Checkboxes!

This topic is 4765 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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]

Share this post


Link to post
Share on other sites
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:


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);

Share this post


Link to post
Share on other sites
Thank you very much for both of you guys, it works very well and it was so simple to resolve that, but i'm not a expert in delphi but a amateur yet, thank you for your attention and precious help!

UltraMAX

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement