No FindString method in ListView! What to do?

Hi All,

I had a dapper little ListBox which showed an index of files in alphabetic order. Above it, I had a textbox and when the user started typing in a file name, I could use the ListBox.FindString function and select the first matching file.

Now, I also wanted to do some drag and drop and found that ListBox didn't have the DragItem event (and others) but that ListView does. Switching to ListView thus improved certain things.

However, ListView doesn't have the FindString method, and although it does have the eminently helpful EnsureVisible function, I don't know of a nice way to find the first matching items in my list.

Has anyone got an alternative way of doing this

Thanks in advance,

David



Answer this question

No FindString method in ListView! What to do?

  • Janthegroat

    Hi Peter and Tony,

    Sorry for not replying. First Easter happened, and then I got caught up with solving my issues. I was trying to implement an index feature just like in VS help (i.e. an edit box to type in and a list showing the matching topics). I wanted to use ListView as I liked the DragItem event which ListBox doesn't have. Anyway, I couldn't get the required functionality with ListView or ComboBox and so I went back to a TextBox plus a ListBox and managed to solve some issues I was having with these.

    I posted my results in the thread ..."Creating an Index feature just like VS Help".

    See...

    http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=358692&SiteID=1

    Thanks for your help.

    David


  • Peter Manse

    Hi David,

    I am just checking to see how this is going.
    Did Tony's suggestion help you
    Please drop me a quick note at your convenience to let me know the current status of this issue.
    If you have any concerns, please do not hesitate to let me know.
    Thanks, and have a great day! :)

    Best regards,
    Peter Huang



  • Antoine.Pourrat

    I use the following code in a command button, but nothing is selected! Why

    Regards
    Kapalic



  • Lisa Feigenbaum

    Wow ... I think you better try posting again.

  • Mike Guilinger

    Tony,

    Interesting function! It isn't mentioned in my msdn help, but I do have it.

    However, how can I now select this item in the list With ListBox, I could do ...

    index = listBox1.FindString(txt);

    listBox1.SelectedIndex = index;

    I'm getting the impression that I'm using the wrong control. I can get the selected items collection, but you can't add to it!!!

    For example, what control is used in the left-hand-side of the Microsoft Document Explorer (msdn help).

    David


  • SlitCanvas

    Hi David,

    I appreciate your prompt response and knowledge sharing!: )

    If you have any other concern, please feel free to post back. I am always very happy to be of assistance.

    Have a nice day!

    Best regards,
    Peter Huang



  • SkyBlade!

    As far as selecting the found item, try this:

    Dim lvi As ListViewItem = MyListView.FindItemWithText(searchString)
    lvi.Selected = True

    Tony


  • jalchr

    Did you try the ListView.FindItemWithText method

    Tony


  • No FindString method in ListView! What to do?