Board index » cppbuilder » TCheckListBox - Problems checking items

TCheckListBox - Problems checking items

Hi folks.

Using Borland C++ Builder Pro 5, I have a standard TCheckListBox, and adding
items is easy. Checking if they're selected is also easy using the
Selected-property.

According to the help-file, I can use the Selected-property to set the value
as well, meaning that I should be able to check boxes by means of simple
C++-calls. However, this doesn't work.

Example:

    if(Entries->Selected[Counter])
    {
        Criteria++;

This one works just fine, i.e. using the Selected property to check if an
item in the list is selected or not is perfectly easy. Now, I'm trying to
create a "Select All"-button, which should be a walk in the park according
to the help file. However, when I try this:

    for(int Counter = 0; Counter < Entries->Items->Count; Counter++)
    {
        Entries->Selected[Counter] = true;
    }

the application exits the loop at the very first call, saying "List Index
Out of Bounds (0)". What am I doing wrong?

Furthermore, in the help-file, there doesn't seem to be any methods for
selecting items in a TCheckListBox.
Can someone suggest an alternative or tell me if I'm just being a lamer/
idiot?

Please CC to my e-mail at christ...@vizionfactory.dk, thank you.

Kind regards,
Christian Jahnsen

 

Re:TCheckListBox - Problems checking items


for (int i=0; i<CheckListBox1->Items->Count;i++)
  Edit1->Text=CheckListBox1->Checked[i]?"Checked":"Not checked";

CheckListBox1->Checked[0]=true;

Re:TCheckListBox - Problems checking items


Quote
Christian Jahnsen wrote:
> Using Borland C++ Builder Pro 5, I have a standard TCheckListBox, and
> adding items is easy. Checking if they're selected is also easy using
> the Selected-property.

There's a difference between 'selected' and 'checked'.
Have a look at the help again, especially for 'State' and 'Checked'.

Jan

Re:TCheckListBox - Problems checking items


Use the Checked[] property, not Selected[], to query and change the
checkboxes themselves.  Selected[] is for the listbox items themselves, not
the checkboxes.

Gambit

Quote
"Christian Jahnsen" <christ...@vizionfactory.dk> wrote in message

news:3d6382a5$1@newsgroups.borland.com...
Quote
> Now, I'm trying to create a "Select All"-button, which
> should be a walk in the park according to the help file.

Other Threads