Hello! I wonder if someone can help me. I have a combobox named Requirements and The values of it come from sql. I want to ask how can I detect if I already selected one item to avoid selecting it again the next time I dropdown the combo box. Thank you very much and God Bless. :D

Maybe not the best way to do it, but...

You can set a variable equal to the selected value (would have to be global inside the class). Then in your .SelectedIndexChanged function, you can put your code inside an If statement that tests to see if the newly selected value is the same as before.

There might be some better ways to do this, but that would work... i think!

Good Luck!

Hi! I got your idea but I think that would only work after 1 selectedindex. Because since, I have more items and what I need is to check if item/s have already been selected before. Thank you and God Bless. :)

See if this helps.

Public Class Form1
    Private myCoolList As New List(Of Integer) '// List to store your SelectedIndexes.

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        If Not myCoolList.Contains(ComboBox1.SelectedIndex) Then '// check if not already added.
            myCoolList.Add(ComboBox1.SelectedIndex) '// add to list.
        Else
            MsgBox("This item has been previously viewed.") '// alert if already viewed.
        End If
    End Sub
End Class
myCoolList.Clear() '// Clear the List if needed.

Thanks! It works. God Bless both of you. :)

Dim a, selected, prev As Integer
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        a = 1
        selected = 0
    End Sub

 a = a << ComboBox1.SelectedIndex
        If (Convert.ToBoolean(selected And a)) Then
            ComboBox1.SelectedIndex = prev
        Else
            selected = selected Or a
            a = 1
            prev = ComboBox1.SelectedIndex
        End If

Originally posted by codeorder

What happen in this code it uses extra amount of memory and when we selected the item which is previously once selected just give a message but that selected with message.

Check If my code is work for you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.