Eleminate duplicate items in a listbox

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
 
O

One Handed Man \( OHM - Terry Burns \)

'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
 
P

Partha Protim Roy

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
 
C

Cor Ligthert

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
 
O

One Handed Man \( OHM - Terry Burns \)

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
 
C

Cor Ligthert

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top