Searching Items

Better ListView offers many options for searching items by typing on keyboard and programmaticaly (FindItemWithText, FindItemsWithText methods). Search can be extended to sub-items and event multiple items can be contained in a search result.

Search can be customized with SearchSettings property. This structure contains three other properties:

There is a default one-second delay to register when user stopped typing and the search is discarded. A new search is initiated when user starts typing after this interval has passed. This interval can be set via SearchTimeoutDelay property.

The delay is not relevant when user types the same letter several times and there are other items beginning with that letter. If there are items named ab, ac, ad, then the selection cycles through these items as long as the user keeps pressing A key. This works essentialy the same way as in the Windows Explorer.

The keyboard search works, of course, only when the control has focus. You can ensure this (e.g. when showing the form) by calling Focus method on Better ListView.

Sample Source Code



// fill the ListView with items in two columns
        new BetterListViewColumnHeader("Word", 128),
        new BetterListViewColumnHeader("Synonym List", 160)

        new BetterListViewItem(new[] { "apparently", "evidently, presumably, seemingly" }),
        new BetterListViewItem(new[] { "blunt", "brusque, curt, snippy" }),
        new BetterListViewItem(new[] { "class", "caste, estate, folk" }),
        new BetterListViewItem(new[] { "detailed", "elaborate, full, thorough" }),

// search in substrings
BetterListViewSearchMode searchMode = BetterListViewSearchMode.Substring;

// use case-sensitive searching and play sounds
BetterListViewSearchOptions searchOptions = (BetterListViewSearchOptions.CaseSensitive | BetterListViewSearchOptions.PlaySound);

// search in the first and second column
//NOTE: empty array also means searching in all columns
int[] subItemIndices = new[] { 0, 1 };

// set-up the search
this.listView.SearchSettings = new BetterListViewSearchSettings(searchMode, searchOptions, subItemIndices);


Visual Basic


' fill the ListView with items in two columns
    New BetterListViewColumnHeader() { _
                                         New BetterListViewColumnHeader("Word", 128),
                                         New BetterListViewColumnHeader("Synonym List", 160)

    New BetterListViewItem() { _
                                 New BetterListViewItem(New String() _
                                                            {"apparently", "evidently, presumably, seemingly"}),
                                 New BetterListViewItem(New String() {"blunt", "brusque, curt, snippy"}),
                                 New BetterListViewItem(New String() {"class", "caste, estate, folk"}),
                                 New BetterListViewItem(New String() {"detailed", "elaborate, full, thorough"})

' search in substrings
Dim searchMode As BetterListViewSearchMode = BetterListViewSearchMode.Substring

' use case-sensitive searching and play sounds
Dim searchOptions As BetterListViewSearchOptions =
        (BetterListViewSearchOptions.CaseSensitive Or BetterListViewSearchOptions.PlaySound)

' search in the first and second column
'NOTE: empty array also means searching in all columns
Dim subItemIndices As Integer() = New Integer() {0, 1}

' set-up the search
ListView.SearchSettings = New BetterListViewSearchSettings (searchMode, searchOptions, subItemIndices)