• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 281
  • Last Modified:

How to check if a Listbox already contains a value?

Hi Guys

Just need a quick hint with fixing a Check for Listbox contains value statement.

The code below does not return my Msgbox as it should.

Dim MyService As New ListView
        MyService.Text = NewServiceTextBox.Text
        If ListBox12.Items.Contains(MyService.Text) = True Then
            MsgBox("Service Exists")
        End If

Open in new window

0
SasfinSD
Asked:
SasfinSD
  • 2
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
use:
If not ListBox12.Items.FindByValue(MyService.Text) is Nothing) then

Open in new window

0
 
SasfinSDAuthor Commented:
I'm using Vs2008

FindbyValue is not a member of "System.Windows.Forms.ListBox.ObjectCollection

What now?
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I see...
Dim MyService As New ListView
        MyService.Text = NewServiceTextBox.Text
        If ListBox12.Items.IndexOf(MyService.Text) >= 0 Then
            MsgBox("Service Exists")
        End If

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now