DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: ListBox Multi Selection Help  (Read 11,709 times)

fmwyso

  • Participant
  • Joined in 2008
  • *
  • Posts: 5
ListBox Multi Selection Help
« on: November 08, 2008, 07:54 PM »
Hey, I love C++ Builder and it has surpassed VC++ in every way so far...

But there is currently one problem that I can't seem to find out... I need to get all the selected strings from a ListBox and I can't find out what function/variable I need to use to do so?

What I want:

An array/list of the strings that are selected inside of a listbox. (Or the indexes of them, I know how to do for loops and how to grab the string at a certain index).

Any help is appreciated (Even a forum where the answer may be easier to get),

  fmwyso

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,931
    • Gathering Badge
    • Plugin Coding Medal
    • Participated in NANY Challenge Seventeen Times
    • Cody Award
    • Coding Snacks
    • Volunteers/Staff
Re: ListBox Multi Selection Help
« Reply #1 on: November 08, 2008, 08:57 PM »
The TCheckListBox component has a property called "State" which is indexed by the item number, and returns cbChecked if its checked, or cbUnchecked if not.

so for example if you have
Code: (cpp)
TCheckListBox *mylistbox;

and you want to see what items are checked you could do

Code: (cpp)
for (int i=0;i<mylistbox->Items->Count;++i)
{
  if (mylistbox->State[i]==cbChecked)
    {
    // item #i is checked
    }
}

fmwyso

  • Participant
  • Joined in 2008
  • *
  • Posts: 5
Re: ListBox Multi Selection Help
« Reply #2 on: November 08, 2008, 09:54 PM »
Hey, I checked over the variables again to look for something that was like State... and Found Selected which I apparently tried wrongly before ><... But now I got it working and thanks :D

Thanks for your help,

  fmwyso
« Last Edit: November 08, 2008, 09:59 PM by fmwyso »

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,931
    • Gathering Badge
    • Plugin Coding Medal
    • Participated in NANY Challenge Seventeen Times
    • Cody Award
    • Coding Snacks
    • Volunteers/Staff
Re: ListBox Multi Selection Help
« Reply #3 on: November 08, 2008, 09:58 PM »
sorry i misread.  You can do *exact* same thing just use the property Selected[i] which returns true if it is selected.

fmwyso

  • Participant
  • Joined in 2008
  • *
  • Posts: 5
Re: ListBox Multi Selection Help
« Reply #4 on: November 08, 2008, 10:00 PM »
xD, just edited last post... I coulda swore I tried the selected... But i think i used the parenthesis instead of brackets ><.

Thanks for your help :P.

K.Sagar

  • Participant
  • Joined in 2009
  • *
  • Posts: 1
Re: ListBox Multi Selection Help
« Reply #5 on: August 13, 2009, 06:42 AM »
Hi,
I am using TList for collection of objects. When my List index do not contain any object it returns me Index out of bound Exception. But I want to Check List before it gives exception.
Plz Help.

Original address: https://www.donationcoder.com/forum/index.php?topic=15652.0