[VB] adding an item to a combobox
Nico
-
Hasstag Posted messages 7 Status Membre -
Hasstag Posted messages 7 Status Membre -
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 réponses
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..
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,
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.
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.
I hope to have a response as soon as possible, and thank you in advance.