Click here to Skip to main content
15,888,320 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I copy all the items (strings) of listbox to a stringlist object? All help sources only show how to copy a stringlist to a listbox.items, I want to do it the other way around. How is that done?

As an addition, how can only the selected (checked items) be copied to a StringList?
Posted
Updated 29-Jun-12 1:16am
v2

1 solution

Delphi
for i := 0 to CheckListBox1.Items.Count - 1 do
  begin
    if CheckListBox1.Checked[i] then
    begin
      sl.Add(CheckListBox1.Items.Strings[i]);
    end;
  end;


You can use Selected instead of Checked to get the selected items in a listbox.

Good luck!
 
Share this answer
 
Comments
Winston_D 29-Jun-12 8:09am    
Thanks, I was curious if there was something like

StringList := CheckListBox.Items;

That could be done.. The above code doesn't work however, something in similar simplicity.

Tnx for the help though!
E.F. Nijboer 29-Jun-12 10:34am    
The problem is that the TStrings (ListBox uses TListBoxStrings internally) is very inefficient to store the checked and selected string values. That's why it simply uses an array of boolean values.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900