Board index » cppbuilder » if (TListBox->MultiSelect == false) TListBox->Selected = readonly ?; take 2

if (TListBox->MultiSelect == false) TListBox->Selected = readonly ?; take 2

When I set the MultiSelect property of a TListBox component to false,
I can no longer SET the contents of the TListBox->Selected property in my
code.

So,
It's not the reading of Selected that I have a problem with, it's the
writing !
After filling the list (in code), I want to select the first item (in code).
This does work when MultiSelect is true, but doesn't when MultiSelect is
false.

I get a 'listindex of bounds[0]' error ... and there are items (and I check
TListbox->Items->Count first, of course).

Is this done on purpose by Borland ?

Adrian.

 

Re:if (TListBox->MultiSelect == false) TListBox->Selected = readonly ?; take 2


if you want to select one item in a listbox, use the itemindex property to
do that.
mylistbox->itemindex = 0; //selects the first entry in the list
don't know if do it at this way, but if select more or find out what is
selected use the selected property like this
mylistbox->selected[4] = true;
mylistbox->selected[5] = true; //selects the 5 and 6 item in the list
or
for (int i=0; i < mylistbox->items->count; ++i)
{
    if (mylistbox->selected[i])
        showmessage("item " + IntToStr(i) + " is selected");

Quote
}

hope it helps :)

"Adrian" <AHeest...@hotmail.com> schrieb im Newsbeitrag
news:3cb43f21$1_2@dnews...

Quote
> When I set the MultiSelect property of a TListBox component to false,
> I can no longer SET the contents of the TListBox->Selected property in my
> code.

> So,
> It's not the reading of Selected that I have a problem with, it's the
> writing !
> After filling the list (in code), I want to select the first item (in
code).
> This does work when MultiSelect is true, but doesn't when MultiSelect is
> false.

> I get a 'listindex of bounds[0]' error ... and there are items (and I
check
> TListbox->Items->Count first, of course).

> Is this done on purpose by Borland ?

> Adrian.

Re:if (TListBox->MultiSelect == false) TListBox->Selected = readonly ?; take 2


Use ItemIndex when multiselect is false - it's in the help files
Rgds Pete

Quote
"Adrian" <AHeest...@hotmail.com> wrote in message news:3cb43f21$1_2@dnews...
> When I set the MultiSelect property of a TListBox component to false,
> I can no longer SET the contents of the TListBox->Selected property in my
> code.

> So,
> It's not the reading of Selected that I have a problem with, it's the
> writing !
> After filling the list (in code), I want to select the first item (in
code).
> This does work when MultiSelect is true, but doesn't when MultiSelect is
> false.

> I get a 'listindex of bounds[0]' error ... and there are items (and I
check
> TListbox->Items->Count first, of course).

> Is this done on purpose by Borland ?

> Adrian.

Other Threads