By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,033 Members | 1,270 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,033 IT Pros & Developers. It's quick & easy.

Eleminate duplicate items in a listbox

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
'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

"mamatha" <ma***********@yahoo.com> wrote in message
news:40****************************@phx.gbl...
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

Nov 21 '05 #2

P: n/a
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
"mamatha" <ma***********@yahoo.com> wrote in message
news:40****************************@phx.gbl...
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

Nov 21 '05 #3

P: n/a
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
Nov 21 '05 #4

P: n/a
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

"Cor Ligthert" <no************@planet.nl> wrote in message
news:Og**************@TK2MSFTNGP09.phx.gbl...
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

Nov 21 '05 #5

P: n/a
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
Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.