Results 1 to 6 of 6

Thread: Check If Strings Is In ListView Items

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2010
    Posts
    33

    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 : ?
    Last edited by smokey2k; May 19th, 2010 at 01:19 PM.

  2. #2
    Addicted Member BSA01's Avatar
    Join Date
    Apr 2009
    Location
    Bosnia and Herzegovina
    Posts
    146

    Re: Check If Strings Is In ListView Items

    Quote Originally Posted by smokey2k View Post
    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

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4

    Thread Starter
    Member
    Join Date
    Apr 2010
    Posts
    33

    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
    Last edited by smokey2k; May 19th, 2010 at 02:00 PM. Reason: Added The Link 4All To Learn OPEN-SOURCE_FTW!

  5. #5
    Addicted Member BSA01's Avatar
    Join Date
    Apr 2009
    Location
    Bosnia and Herzegovina
    Posts
    146

    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

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width