Hi Alls,
I got problem here to check whether the value in listbox more than one or already exist....I already do this code but it just check existing value only not count if it more than that,,,,anyone can show me the way plz...
Hi Alls,
I got problem here to check whether the value in listbox more than one or already exist....I already do this code but it just check existing value only not count if it more than that,,,,anyone can show me the way plz...
Have you tried looping through the listbox's items property with an integer to keep track of the count?
The code would be like this:
Dim IntegerVariable as integer = 0
if TheListBox.Items.Contains("LookForMyString") then
For each obj as object in TheListBox.Items
If obj.tostring = "LookForMystring" then IntegerVariable+=1
'or
'If Obj.ToString= "LookForMyString" Then IntegerVariable = 'Integervariable +1
Next
end if
Note: I'm having to reinstall VS right now, so I had to aircode this and haven't been able to check the syntax, but I believe it to be correct.
Is that what you're looking for?
I'm think it not that i need...ekekeek...actually i need to check whether the value that been enter in textbox already exists in listboxs more than one or not....if have..display msgbox alert...if not just ignore...tq...hope u help me
if you just want to check if entry exist no matter how often then this is the way to go:
if ListBox1.FindStringExact(textbox1.text) then
msgbox "entry already exist"
end if
Hi!
I think your requirement is as follows.
Dim strToFind As String
Dim i As Integer = 0
strToFind = TextBox1.Text
For Each item As Object In ListBox1.Items
If item.ToString().ToUpper() = strToFind.ToUpper() Then
i += 1
End If
If i > 1 Then
MsgBox("Item exists in the listbox more than one time.")
Exit For
End If
Next
if you want to use the idea from the poster above then it's might be easier to do since the second IF condition is not really needed.
Dim strToFind As String
strToFind = TextBox1.Text
For Each item As Object In ListBox1.Items
If item.ToString().ToUpper() = strToFind.ToUpper() Then
MsgBox("Item exists in the listbox more than one time.")
Exit For
End If
Next
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.