If cboCar.Text <> cboCar.List(cboCar.ListIndex) Then Do cboCar.AddItem cboCar.Text ''Add to combo box Loop Until cboCar.Text <> cboCar.List(cboCar.ListIndex) Else MsgBox "Already There" ''Display Textbox if it's in the combo box already End If
help on combobox
Started by Gz1987, Mar 17 2008 09:51 PM
4 replies to this topic
#1
Posted 17 March 2008 - 09:51 PM
My question is: How do you prevent the user from entering the same data to the combobox? I know you need a do loop and an if statement. but tried to do that for awhile and only little luck. I will post my code below. The code works sometimes, but i think there must be some logic error within.
|
|
|
#2
Guest_Jordan_*
Posted 18 March 2008 - 12:32 PM
Guest_Jordan_*
Your loop is wrong. You are saying:
Index1 = this
Index2 = that
cboCar.Text = that
Loop starts at index1. cbCar.Text does not equal Index1. Loop ends. Loop stops at index1. You see, you are never making it to index2 or beyond. Use a do for or while loop with a counter. Cycle through every index until the end. If no matches were found, add the item.
You can also use a search function, if it returns false then insert the word:
Progressive Search Using a Combobox in VB.NET 2005
Index1 = this
Index2 = that
cboCar.Text = that
Loop starts at index1. cbCar.Text does not equal Index1. Loop ends. Loop stops at index1. You see, you are never making it to index2 or beyond. Use a do for or while loop with a counter. Cycle through every index until the end. If no matches were found, add the item.
You can also use a search function, if it returns false then insert the word:
Progressive Search Using a Combobox in VB.NET 2005
#3
Posted 18 March 2008 - 10:13 PM
Thank you, i know what i am doing wrong now. but i ran into another trouble spot. for the "For loop" i know i am suppose to loop through the list, but i cannot seem to find the right property for it. is it ".ListIndex", ".List"
#4
Guest_Jordan_*
Posted 19 March 2008 - 04:43 AM
Guest_Jordan_*
I'm not sure I understand what you are asking. The total number of entries in the combobox would be ".ListCount". The ListIndex is the currently selected item.
Here is a sample for loop:
I didn't test or execute this code so there could be errors.
Here is a sample for loop:
For i = 0 To cboCar.ListCount Step 1
if cboCar.Text <> cboCar.List(cboCar.ListIndex) Then
' Entry already in list
End If
Next i
I didn't test or execute this code so there could be errors.
#5
Posted 29 March 2008 - 04:41 PM
ohh it all makes sense


Sign In
Create Account


Back to top









