ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Removed Areas > Delphi and C++ Builder

ListBox Multi Selection Help

(1/2) > >>

fmwyso:
 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:
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++ ---TCheckListBox *mylistbox;
and you want to see what items are checked you could do


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

fmwyso:
 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

mouser:
sorry i misread.  You can do *exact* same thing just use the property Selected[i] which returns true if it is selected.

fmwyso:
 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.

Navigation

[0] Message Index

[#] Next page

Go to full version