On Tue, 20 Nov 2007 04:39:00 -0800, Mahmoud Shaban <Mahmoud
(E-Mail Removed)> wrote:
>i have a problem in adding new listbox items
>
>i don't need to allow adding multible items with the same textvalue
>
>ex: if current items are:
>
>green
>
>red
>
>blue
>
>if red is tried to be added again then error
>
>i thinked about the possible solution:
>
>1.read the current values in listbox in an array
>2.compare the textbox textvalue with the all current items textvalues with
>if statement
>3.raise message error if the textbox textvalue = any item textvalue not the
>selected item
>
>any help in how to achieve that by code
>
>by the way
>
>i'm new to C# ,my experience doesn't exceed one year,and i started
>programming with studying VB.net but i was not involved in large projects and
>i need to go in the right track
>so
>first i need some tips helping me go faster in programming in general.
>
>second what is the best way to get stareted in any new topic (C# as a
>langage,ASP.net 2.0,AJAX,...................... and other new technology
>
>thanks for everyone
Hi,
Another possibility is to add the items to a dictionary first.
You can use the dictionary ContainsKeymethod to check if a value is
already there, if it is not present, add it to the dictionary and to
the listbox. If it is already in the dictionary then advise the user.
This avoids iterating over the list. For a small list it is of no
advantage for a large list there may be savings.
hth
Bob