FuzzySort
FuzzySort improves the type-ahead search of a Wisej.NET ComboBox. As the user types, the drop-down list keeps only the items that contain the typed text, and the matching characters of each item are highlighted. The matching and highlighting run entirely in the browser, with the fuzzysort library (version 3.1.0), so the list responds instantly with no server round trip.
Installation
Add the Wisej-4-FuzzySort package to your Wisej.NET project:
dotnet add package Wisej-4-FuzzySort
The package targets .NET Framework 4.8 and .NET 8 or later. It adds no control to the toolbox. Instead, it adds an extension method to the ComboBox you already use.
Getting started
Fill a ComboBox and call ApplyFuzzySort() on it:
- C#
- VB.NET
using Wisej.Ext.FuzzySort;
var comboBox = new ComboBox
{
Width = 250,
Location = new Point(20, 20)
};
comboBox.Items.AddRange(new object[]
{
"Apple", "Banana", "Grape", "Pineapple",
"Orange", "Apricot", "Blueberry", "Blackberry"
});
this.Controls.Add(comboBox);
// Enable the fuzzy search. The method returns the same ComboBox, so calls can be chained.
comboBox.ApplyFuzzySort();
Imports Wisej.Ext.FuzzySort
Dim comboBox As New ComboBox With {
.Width = 250,
.Location = New Point(20, 20)
}
comboBox.Items.AddRange(New Object() {
"Apple", "Banana", "Grape", "Pineapple",
"Orange", "Apricot", "Blueberry", "Blackberry"
})
Me.Controls.Add(comboBox)
' Enable the fuzzy search. The method returns the same ComboBox, so calls can be chained.
comboBox.ApplyFuzzySort()
For a ComboBox placed in the designer, call ApplyFuzzySort() once in the page's or form's constructor, after InitializeComponent().
How it works
ApplyFuzzySort() does three things:
- It sets the combo box's
AutoCompleteModetoFilter, so the drop-down list shows only the items that match what the user types. - It installs a filter that keeps an item when its text contains the typed text anywhere, ignoring case. That's why Grape and Pineapple stay in the list for "ap" in the screenshot.
- It runs fuzzysort over the visible items and highlights the matched characters in red.
The items keep their original order in the list. Highlighting marks each match but doesn't sort the list by score.
The extension works only in the Filter auto-complete mode. If you set AutoCompleteMode to any other value after calling ApplyFuzzySort(), the fuzzy filtering stops.
Highlighting turns the drop-down items into rich (HTML) labels, so any markup in an item's text is rendered rather than shown literally. Don't use this on a ComboBox whose items can contain < or & characters from user input.
API reference
FuzzySort.ApplyFuzzySort- The whole
Wisej.Ext.FuzzySortnamespace ComboBoxin the Wisej.NET API, and ComboBox in the user guide