Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • May 31, 2016, 12:52:42 AM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: ListBox Multi Selection Help  (Read 5876 times)

fmwyso

  • Participant
  • Joined in 2008
  • *
  • default avatar
  • Posts: 5
    • View Profile
    • Donate to Member
ListBox Multi Selection Help
« on: November 08, 2008, 01:54:15 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: 35,968
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Donate to Member
Re: ListBox Multi Selection Help
« Reply #1 on: November 08, 2008, 02:57:34 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: C++ [Select]
  1. TCheckListBox *mylistbox;

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

Code: C++ [Select]
  1. for (int i=0;i<mylistbox->Items->Count;++i)
  2. {
  3.   if (mylistbox->State[i]==cbChecked)
  4.     {
  5.     // item #i is checked
  6.     }
  7. }

fmwyso

  • Participant
  • Joined in 2008
  • *
  • default avatar
  • Posts: 5
    • View Profile
    • Donate to Member
Re: ListBox Multi Selection Help
« Reply #2 on: November 08, 2008, 03:54:02 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, 03:59:31 PM by fmwyso »

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 35,968
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Donate to Member
Re: ListBox Multi Selection Help
« Reply #3 on: November 08, 2008, 03:58:27 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
  • *
  • default avatar
  • Posts: 5
    • View Profile
    • Donate to Member
Re: ListBox Multi Selection Help
« Reply #4 on: November 08, 2008, 04:00:12 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
  • *
  • default avatar
  • Posts: 1
    • View Profile
    • Donate to Member
Re: ListBox Multi Selection Help
« Reply #5 on: August 13, 2009, 01:42:20 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.