|
-
Feb 14th, 2009, 03:18 PM
#1
Thread Starter
Fanatic Member
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
-
Feb 14th, 2009, 03:29 PM
#2
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
-
Feb 14th, 2009, 03:32 PM
#3
Re: Listbox Item Exist validation......ignore case?
You could use the FindStringExact method as its not case sensitive.
Casey.
-
Feb 14th, 2009, 03:40 PM
#4
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
-
Feb 14th, 2009, 03:57 PM
#5
Thread Starter
Fanatic Member
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.
-
Feb 14th, 2009, 04:00 PM
#6
Re: Listbox Item Exist validation......ignore case?
Hi,
Your welcom.
If it solves your problem, mark your thread as resolved!
Wkr,
sparrow1
-
Feb 20th, 2009, 10:07 AM
#7
Thread Starter
Fanatic Member
Re: Listbox Item Exist validation......ignore case?
That took care of it. Thanks for the assistance.
-Jeremy
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|