Listbox Item Exist validation......ignore case?
I have written the code below to check and see if the text the user entered into the txtbox already exists as an item in a listbox before adding the new item. This works well; however, if say "Fish" exists in the listbox but the user entered "fish" in the textbox, the item is added to the listbox. I do not want this because the item already exists. How can I modify my code so that the comparison is not case sensitive? Any tips appreciated.
Code:
'Check to make sure the active medication does not already exists in the list
If lstActiveMeds.Items.Contains(strActiveMeds) = True Then
MessageBox.Show("The active medication you entered has already been added to the list.", "Error")
txtActiveMeds.Text = ""
txtActiveMeds.Focus()
Else
'Add the Active Medication to the list
lstActiveMeds.Items.Add(strActiveMeds)
txtActiveMeds.Text = ""
txtActiveMeds.Focus()
End If
Re: Listbox Item Exist validation......ignore case?
Hi,
That's normal because this part of your code says to do so;
vb Code:
'Add the Active Medication to the list
lstActiveMeds.Items.Add(strActiveMeds)
txtActiveMeds.Text = ""
txtActiveMeds.Focus()
wkr,
sparrow1
Re: Listbox Item Exist validation......ignore case?
You could use the FindStringExact method as its not case sensitive.
Casey.
Re: Listbox Item Exist validation......ignore case?
Hi,
You could change this:
vb Code:
lstActiveMeds.Items.Contains(strActiveMeds) = True
into
vb Code:
lstActiveMeds.Items.Contains(strActiveMeds.ToString().Upper()) = True
Wkr,
sparrow1
Re: Listbox Item Exist validation......ignore case?
Thanks Sparrow. I think that will work just fine for my application. I less concerned about the case of the first letter, but more about duplicates. Thanks.
Re: Listbox Item Exist validation......ignore case?
Hi,
Your welcom.
If it solves your problem, mark your thread as resolved!
Wkr,
sparrow1
Re: Listbox Item Exist validation......ignore case?
That took care of it. Thanks for the assistance.
-Jeremy