checks if the item is already selected once in combobox
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
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!
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. :)
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.
MsgBox("This item has been previously viewed.") '// alert if already viewed.
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
a = a << ComboBox1.SelectedIndex
If (Convert.ToBoolean(selected And a)) Then
ComboBox1.SelectedIndex = prev
selected = selected Or a
a = 1
prev = ComboBox1.SelectedIndex
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.
I am writing a java program that needs to execute shell commands, so I wrote a function that would take the command to execute as a string (ie: "mkdir ~/Folder1") and execute that command with the shell. Here is the function:
Runtime run = Runtime.getRuntime();
Process pr = ...
Hi, as I was told that my code doesn’t scale well at all, I thought perhaps I’d try to get a better understanding of interfaces/abstract classes and classes and the relationship between them.
I don’t want at this stage work on a big separate project as I've already got plenty ...
Hi. I have a form with list box : lst_product, datagridview : grd_order and button: btn_addline. lst_product has a list of product ids selected from database (MS Acess 2013) , grd_order is by default empty except for 2 headers and btn_addline adds rows to grd_order.