Board index » cppbuilder » newbie problem with listbox

newbie problem with listbox

Hi

I wonder if there is an easy way to see if a item already exist in a
listbox.

example

let say I have 4 items in a listbox, and the user want to add a new
item. But I do not want him to add a item which already exist, so I must
compare all 4 items with the item which the user want to add.

Any easy way to do that?

Regards
William

 

Re:newbie problem with listbox


Quote
> let say I have 4 items in a listbox, and the user want to add a new
> item. But I do not want him to add a item which already exist, so I must
> compare all 4 items with the item which the user want to add.

lbMyBox->Strings->IndexOf("alreadythere")
will return its index if it's already there, or -1 if not.

--
Lucian

Re:newbie problem with listbox


Hello Hoang,

Hoang Trung <ei99h...@chl.chalmers.se> schreef in berichtnieuws
3A0C0BA6.AE9AB...@chl.chalmers.se...

Quote
> Hi

> I wonder if there is an easy way to see if a item already exist in a
> listbox.

Do something like:

int index;
if( (index = ListBox->Items->IndexOf("A new Entry")) > -1 )
    ListBox->ItemIndex = index;
else {
    index = ListBox->Items->Add("A new Entry");
    ListBox->ItemIndex = index;

Quote
}
> Any easy way to do that?

Is this easy enough...;-))

Quote
> William

--
Greetings from overcast Amsterdam

                Jan

email: bijs...@worldonline.nl
http://home.worldonline.nl/~bijster

Other Threads