Results 1 to 7 of 7

Thread: Listbox Item Exist validation......ignore case?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    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

  2. #2
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: Listbox Item Exist validation......ignore case?

    Hi,

    That's normal because this part of your code says to do so;

    vb Code:
    1. 'Add the Active Medication to the list
    2.             lstActiveMeds.Items.Add(strActiveMeds)
    3.             txtActiveMeds.Text = ""
    4.             txtActiveMeds.Focus()

    wkr,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  3. #3
    Fanatic Member vbasicgirl's Avatar
    Join Date
    Jan 2004
    Location
    Manchester, UK
    Posts
    1,016

    Re: Listbox Item Exist validation......ignore case?

    You could use the FindStringExact method as its not case sensitive.

    Casey.

  4. #4
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: Listbox Item Exist validation......ignore case?

    Hi,

    You could change this:

    vb Code:
    1. lstActiveMeds.Items.Contains(strActiveMeds) = True
    into

    vb Code:
    1. lstActiveMeds.Items.Contains(strActiveMeds.ToString().Upper()) = True

    Wkr,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    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.

  6. #6
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: Listbox Item Exist validation......ignore case?

    Hi,

    Your welcom.
    If it solves your problem, mark your thread as resolved!

    Wkr,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    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
  •  



Click Here to Expand Forum to Full Width