Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have used two textboxes and stored there value in a list.
ListBox1.Items.Add(TextBox1.Text + "" + TextBox2.Text)

Now i want to add a check of already existing so that same value does n't go in the list.Any body please help its urgent ..!!!!!!!!!!!!
Posted
Comments
Maciej Los 14-Nov-15 2:03am    
What is stopping you?
Member 12119549 14-Nov-15 2:17am    
For Each item As var In ListBox1.Items
If item <> TextBox1.Text + "" + TextBox2.Text Then
ListBox1.Items.Add(TextBox1.Text + "" + TextBox2.Text)
End If
Next

i have used it in vb.. its giving be error on var..plz help?
Afzaal Ahmad Zeeshan 14-Nov-15 2:27am    
The var is in C#, in VB.NET you need to write the type. Perhaps, it would be ListBoxItem.
Member 12119549 14-Nov-15 2:31am    
completly stuck :( didnt get you sir

1 solution

C#
foreach(var item in ListBox1.Items)
{
    if(item != TextBox1.Text + "" + TextBox2.Text){
        ListBox1.Items.Add(TextBox1.Text + "" + TextBox2.Text);
    }
}

-KR
 
Share this answer
 
v2
Comments
Member 12119549 14-Nov-15 2:08am    
Thanks for your responce,can you please tell what is var in it..getting error while conveeting it :(
Member 12119549 14-Nov-15 2:22am    
@Rohit???
Krunal Rohit 14-Nov-15 2:46am    
For Each item As String In ListBox1.Items
If item <> TextBox1.Text + "" + TextBox2.Text Then
ListBox1.Items.Add(TextBox1.Text + "" + TextBox2.Text)
End If
Next
Afzaal Ahmad Zeeshan 14-Nov-15 2:26am    
He is using VB.NET, not C#.

Intellect of user forces him to use copy/paste, which brings him down to more problems.
Member 12119549 14-Nov-15 6:24am    
Any help?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900