How to Check the alphanumeric value already exists in Listbox C#.Net

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi All,
How to Check the value already exists in Listbox C#.Net.
My Problem is below like.
I have two forms, One is Form1 and another one is form2. Form1 I have Listbox and Form2 I have one TextBox.
I am adding the value into Listbox what I am enter Form2 Textbox.
I need compare and Check the value already exists or not.
What I am doing is, I am taking the all Listbox values into String List then I am passing that String List Form2.
I am compare the Testbox values in Form2 before adding into the Listbox but it compare only the String and It not compare the numbers.
I am using the below code.
Form1 Code:
<pre class="prettyprint public List<string> CompareNamesNumbers = new List<string>();
string CompareNamesNumbersList = string.Empty;

for (int i = 0; i < listBox1.Items.Count; i++)
{
CompareNamesNumbersList = listBox1.Items.ToString();
CompareNamesNumbers.Add(CompareNamesNumbersList);
} Form2 Code: <pre class="prettyprint if (!CompareNamesNumbers.Contains(txt_EnterNewName.Text, StringComparer.CurrentCultureIgnoreCase))
{
}
else
{
DialogResult DisMesg = MessageBox.Show("The Value is Already Exits!", "Infromation", MessageBoxButtons.OK, MessageBoxIcon.Information);
}[/code]<br/>Please any one can sugessted, How to Check the number value already exists in Listbox.[/code]
<br/>
<hr class="sig Vijay

View the full article
 
Back
Top