validating input on a list box

johnfrench

New member
Joined
Aug 14, 2007
Messages
2
Programming Experience
1-3
Hello,

I have a list box.
I want to be able to say if value 6 or 10 is selected, PLUS one or more of any other value then report an error.

I have so far If lbxBuyingAgencies.Items.FindByValue("6").Selected = True Or lbxBuyingAgencies.Items.FindByValue("10").Selected = True Then

however, how do i say "if any other value is selected aswell"

does any body know a neat way of doing this?

thanks for your help
 
VB.NET:
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        For x As Integer = 1 To 100
            ListBox1.Items.Add(x)
        Next
        'this will make sure that the user only selects one item
        ListBox1.SelectionMode = SelectionMode.One
    End Sub

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        If ListBox1.SelectedItems.Count = 0 Then
            'if nothing is selected

        ElseIf ListBox1.SelectedItems.Count = 1 Then
            'one item is selected

        ElseIf ListBox1.SelectedItems.Count > 1 Then
            'more than 1 selected
            'should never happen because of form load code
        End If

        If ListBox1.SelectedItem.ToString = "6" Then
            'what you want to do if the selected item's value is six
        End If

        If ListBox1.SelectedIndex = 5 Then
            'what you want to do if the 6th item on the list is selected
        End If
    End Sub
End Class
 
Back
Top