469,904 Members | 2,439 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,904 developers. It's quick & easy.

Removing items from a combobox

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
Jul 21 '05 #1
3 5541
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:
If i > 0 Then
For i= 0 To (MyArray.Count - 1)
Combobox1.Items.Remove(MyArray)
Next i
End If
can someone tell me what the problem could be?

thank you

Jul 21 '05 #2
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

Jul 21 '05 #3
Hello Cor

Thank you for your help. My problem is now fix
Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Varun | last post: by
2 posts views Thread by Curious | last post: by
1 post views Thread by Sam | last post: by
reply views Thread by mharness | last post: by
reply views Thread by Pramod Kadur | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.