Eleminate duplicate items in a listbox

  • Thread starter Thread starter mamatha
  • Start date Start date
M

mamatha

Hi
I am developing a VB.NET application,in that application i
have a listbox.When adding items to the listbox some
duplicate items are added,how can i prevent listbox items
from duplication.If any one knows please suggest me.



Mamatha
 
'Test to see if it is already in list

If ListBox1.Items.Contains(TextBox1.Text) Then

MsgBox("This is already in the list")

Else

ListBox1.Items.Add(TextBox1.Text)

End If


--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing
 
Are you loading from the DATABASE.
If 'Yes' then use DISTINCT in the SQL, bound it to listbox, you will only
have distinct item in the list box.

Regards
Partha
 
Partha,
Are you loading from the DATABASE.
If 'Yes' then use DISTINCT in the SQL, bound it to listbox, you will only
have distinct item in the list box.

It is how you read "adding", when this is only the first initial time using
the datasource instead of the "ADD" you are completly correct, when is meant
afterwards this is not true.

Just trying to make it clear, because basicly there is nothing wrong with
your statement, however can be in mine opinion interpretted in another way.

Cor
 
Unfortunatley the OP was not detlailed in his/her discription of the issue.
As no mention of SQL/ACCESS Etc was mentioned, I thought perhaps that they
were adding to the list manually.

I suppose we shall see if the OP replies.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing
 
Terry,

I had the same thought as you before I readed the message from Partha, where
I than thought that becauseof the listbox.add (which can be used to fill and
to add) can as well be true.

:-)

Cor
 
Back
Top