Check If Strings Is In ListView Items
Ok well I hate working with ListView, dont get me wrong its an awesome control and can get us around the file size limitations a normal listbox can handle. However lets be honest the functions of a listbox are allot easier to understand & work with then listview's functions/subs. So I am left wondering how I will pull of this task, basically its comparing a text-based string and checking to see if it lies within ListView's Content(s)/Item(s). Once it finds the item that has the string in it (format for the list it is checking is String:GetData, GetData = Data we need to get and store as string) grab whats to the right of the semi colon in that item (I wrote a function called getLeft/getRight which grabs everything from the left/right of a semicolon) and save it as a string to use later on down the line while sending data.
So my question is how do you go about checking to see if a string is an item within Listview and once it's found set that as a string so program can grab the text to the right of the semi colon : ?
Re: Check If Strings Is In ListView Items
Quote:
Originally Posted by
smokey2k
Ok well I hate working with ListView, dont get me wrong its an awesome control and can get us around the file size limitations a normal listbox can handle. However lets be honest the functions of a listbox are allot easier to understand & work with then listview's functions/subs. So I am left wondering how I will pull of this task, basically its comparing a text-based string and checking to see if it lies within ListView's Content(s)/Item(s).
So my question is how do you go about checking to see if a string is an item within Listview?
try this :
Code:
For i = 1 To ListView1.ListItems.Count
MsgBox ListView1.ListItems.Item(i).Text
Next i
Re: Check If Strings Is In ListView Items
How many columns does your listview have? If only one, you may be able to use its Find method.
If more than one column, which column(s) will this string be in, if it exists?
Re: Check If Strings Is In ListView Items
Well I fixed it thanks to a MSDN refrence...
Code:
Function GetCurrentListItemsWebsite(List1 As ListView) As String
Dim tmpI$
Dim oItem
Set oItem = List1.FindItem(EMAIL$, lvwText, , lvwPartial)
If Not oItem Is Nothing Then
'found item
oItem.Selected = True
List1.SetFocus
Else
'didnt find it
GetCurrentListItemsWebsite = getRight(List1.SelectedItem.Text)
'MsgBox GetCurrentListItemsWebsite
End If
End Function
What this does is look for any item within a listview and return whats to the right of the semi colon, for example the way this list worked was... [email protected]:"Mastic,Shirley,Riverhead,Speonk,South Hampton,Sag Harbor"
so my code was basically a security layer because sometimes the text that my program would grab off the server was missing a city or 2, so I wrote this to compare it & add something if anything was missing so it wasnt a poor "post" lets call it
Also here is the link for refrence, I suggest anyone interested in finding strings within a listview check this out, or anyone wanting to know more about ListView -> http://msdn.microsoft.com/en-us/libr...8VS.60%29.aspx
Re: Check If Strings Is In ListView Items
If you want to have more than one column then use this :
Set "View" property : 3 - lvwReport
For adding :
Code:
ListView1.ListItems.Add i, , "Some text"
this is for adding text to first column
if you want to add to 2nd column, use this :
Code:
ListView1.ListItems(X).SubItems(1) = "Some text, col2"
If you try to add some text to 2nd column, and before that, you didn't added that row, you'll get error.
And, if you want to read first column - use code from #2 reply, else, use SubItems(Index)
EDIT : Didn't see your pos :D
Re: Check If Strings Is In ListView Items
Smokey, don't forget to mark this as resolved now. Do this from the "Thread Tools" dropdown menu near the top of your first post above.