« Saving and Loading ListView Content | Index | Serialization » |
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:
Specifies how the searching is done on each item/sub-item string.
Searching is disabled.
Search is restricted to text prefix.
Search query can match any substring, if nothing found by prefix.
Search query can match any substring.
Additional options for searching.
The search is case-sensitive.
Search is restricted to the first word of searched text.
No options active.
Sound is played, when nothing is found.
Results matched by prefix are prefered among other (e.g. when searching for pla, then the text player is prefered among the word applause).
Restrict the search to selectable items only.
Searched text si first split into words and searching is done on each word separately.
Specifies sub-items on which the search is done; if the collection is empty, than all sub-items are searched.
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.
C#
this.listView.BeginUpdate();
// fill the ListView with items in two columns
this.listView.Columns.AddRange(
new[]
{
new BetterListViewColumnHeader("Word", 128),
new BetterListViewColumnHeader("Synonym List", 160)
});
this.listView.Items.AddRange(
new[]
{
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);
this.listView.EndUpdate();
Visual Basic
ListView.BeginUpdate()
' fill the ListView with items in two columns
ListView.Columns.AddRange(
New BetterListViewColumnHeader() { _
New BetterListViewColumnHeader("Word", 128),
New BetterListViewColumnHeader("Synonym List", 160)
})
ListView.Items.AddRange(
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)
ListView.EndUpdate()
« Saving and Loading ListView Content | Index | Serialization » |
Better ListView Documentation | Copyright © 2010-2012 ComponentOwl.com |