Removing items from a combobox

G

Guest

Hello

I am trying to make the items in my combobox be removed if they are present in my array
I cant however get my code to work. The values are read into my combobox using a datareader. I then want to remove items from the items collection of the combobox if they are in my array. Here is what i try

If i > 0 The
For i= 0 To (MyArray.Count - 1
Combobox1.Items.Remove(MyArray
Next
End I

can someone tell me what the problem could be

thank you
 
C

Cor

Hi Varun,

You have two tables, not one, where the index can be different.
I do not know what kind of array you have and therefore i take another
approach

I have typed it here, so watch errors or typos

\\\
dim i as integer
For i = 0 to MyArray.count -1
'We go through the array
dim y as integer = combobox1.findstringexact(trim(myarray(i)))
'If we find it y is the index of the combobox row else it is -1
if y<>-1 then
combobox1.items.removeAt(y)
end if
next
///
As said not tested just typed here.

You can try it?

Cor

Hello,

I am trying to make the items in my combobox be removed if they are present in my array.
I cant however get my code to work. The values are read into my combobox
using a datareader. I then want to remove items from the items collection of
the combobox if they are in my array. Here is what i try:
 
G

Guest

Hello Cor

The order of the process is the user select item from combobox1. A datareader is run against the DB and used to fill combobox2. User now selsect item from combobox2 and then presses Button1. When button1 is clicked the item chosenin from combobox2 is added to my arraylist.

MyArray.Add(Combobox2.Text
'increment the arrayInde
i= (i+ 1

The whole process is then repeated so another item from combobox2 can be selected

What i want to ensure is that the same item that was selected (i.e those in my arraylist) does not reappear in combobox2
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top