[VB] adding an item to a combobox
Nico
-
Hasstag Posted messages 7 Status Member -
Hasstag Posted messages 7 Status Member -
Hello,
(I am in Visual Basic),
when I click on a button, I add 2 items to my combobox:
macombo.AddItem (mytext1)
macombo.AddItem (mytext2)
but when I click on this button again, it adds the items in double, e.g.:
mytext1
mytext2
mytext1
mytext2
instead of:
mytext1
mytext2
no matter how many times I click the button. I believe there is something with the index property but...
Thank you in advance.
(I am in Visual Basic),
when I click on a button, I add 2 items to my combobox:
macombo.AddItem (mytext1)
macombo.AddItem (mytext2)
but when I click on this button again, it adds the items in double, e.g.:
mytext1
mytext2
mytext1
mytext2
instead of:
mytext1
mytext2
no matter how many times I click the button. I believe there is something with the index property but...
Thank you in advance.
4 answers
-
hello...
just do:
ComboBox1.Clear, before each reload to clear the previous content of the list...
Good luck ! -
hi
You indeed need to specify the index where you should add the Item. So retrieve the number of Items already in the combobox, normally the first index is equal to zero, so number of Items -1 gives you the last used index.
If you have 4 Items, the last one is stored in index 3.
ComboBox1.AddItem("test", ComboBox1.ListIndex);
It should give something like that, to check
--
Chouba,
Assault Pochard.. -
Hello everyone
I've seen some ways to add a list of choices to the combo box, but every time I type the same thing it doesn't work, for example combo1.additem "mytext" or combo1.additem ("mytext", combo1.listindex)
What do you think the solution is??? -
Hello,
I had the same problem, and I wrote this code that checks if the item to be added already exists:
If Form2.TextBox0.Text <> "" Then
For i = 0 To ComboBox1.Items.Count - 1
If ComboBox1.Items(i) = UCase(Form2.TextBox0.Text) Then
C = 1
End If
Next i
If C = 0 Then
ComboBox1.Items.Add(UCase(Form2.TextBox0.Text))
End If
End If
I hope this helps you.