Quantcast
Channel: Developer Express Inc.
Viewing all articles
Browse latest Browse all 2370

WinForms - Automatic Suggestions for Lookup Editors

$
0
0

A couple of years ago, we published a post about our rich collection of WinForms Lookup Editors. In this post, I’ll summarize the main differences between these controls and will explain how to select the appropriate WinForms Lookup for your next WinForms project.

Our upcoming release (v19.2) will include a fabulous new feature for our LookUpEdit and GridLookupEdit controls (automatic suggestions). Before I explain the benefits of this new feature, I want to draw a distinction between it and our existing auto-complete mode. Auto-complete can be enabled with the component’s SearchMode property. When active, auto-complete forces a bound lookup editor to locate records that match the text entered by a user and displays the first item it locates within the lookup:

autocomplete

To activate automatic suggestions (our new feature), you will need to set SearchMode to AutoSuggest. Unlike AutoComplete (which hides non-matching records within the data-bound lookup) AutoSuggest dynamically changes the editor’s data source as users enter text (as such, it can work with completely empty, unbound editors).

AutoSuggest will be available in our upcoming WinForms Early Access Preview build. We’ve created a new module in our XtraEditors demo to demonstrate this feature– stay tuned for detailed articles on usage scenarios. For now, let me quickly describe how it functions so you can decide whether it can address end-user requirements.

Each time a user enters a new character, the lookup editor fires the AutoSuggest event. This event must be handled and assigned a custom System.Threading.Tasks.Task object. This asynchronous cancelable Task must return a collection of records that will be treated as the editor’s source.

1
2
3
4
5
6
7
8
lookUpEdit1.AutoSuggest += OnAutoSuggest; 

voidOnAutoSuggest(objectsender, LookUpEditAutoSuggestEventArgse) {
// Set delay (if needed)
e.SetMinimumAnimationDuration(TimeSpan.FromMilliseconds(1000));
// Assign a Task that return suggestions
e.GetSuggestions = WorldCities.QueryAsync(e.Text, e.CancellationToken);
}

The way you implement Task is completely up to you: in the demo, we parse a huge locally stored Excel file. You can retrieve data from a database file or send SQL queries and retrieve records from a remote server.

autosuggest

When a lookup obtains drop-down items, the editor scans these records and highlights all portions of item captions that match user text. This default logic covers many simple scenarios, but if needed, you’re free to implement custom highlight patterns.

In the demo, our “Enter the city name” lookup is populated by a Task that searches for matches in city and state names. However, lookup records also contain country names. The default highlight pattern does not suit our scenario since it highlights characters within country names (which are ignored by the Task).

highlight

To fix this mismatch, the custom method is assigned to the SetHighlightRanges event parameter.

1
2
3
4
5
voidOnAutoSuggest(objectsender, LookUpEditAutoSuggestEventArgse) { 
//...
// Set Custom Highlight Strategy
e.SetHighlightRanges(HighlightTags(e.Text));
}

Tell Us What You Think!

As I mentioned earlier, we will discuss this feature in greater detail as we near our official release. If you are an active Universal or DXperience subscriber, please keep an eye out for our v19.2 Early Access Preview. Your feedback on this feature (and others planned for v19.2) will help us make our next release the best ever.


Viewing all articles
Browse latest Browse all 2370

Trending Articles