WinForms - Automatic Suggestions for Lookup Editors

WinForms Team Blog
06 August 2019

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; 

void OnAutoSuggest(object sender, LookUpEditAutoSuggestEventArgs e) {
// Set delay (if needed)
e.SetMinimumAnimationDuration(TimeSpan.FromMilliseconds(1000));
// Assign a Task that return suggestions
e.QuerySuggestions = 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
void OnAutoSuggest(object sender, LookUpEditAutoSuggestEventArgs e) { 
//...
// 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.

17 comment(s)
Andrey Makhorin
Andrey Makhorin

Hello!

Suggestion mode is very usefull!

Will wait

6 August, 2019
Andreas Mummenhoff
Andreas Mummenhoff
very good, long awaited :-)
6 August, 2019
_Vincent
_Vincent
Very nice! 
6 August, 2019
Sid Ahmed WeUp
Sid Ahmed WeUp
I've been waiting for this feature. Good one. 
6 August, 2019
Thorsten Sommer
Thorsten Sommer
Great, thanks for this feature. I will use it for my current project. Keep up the good work.
6 August, 2019
Customer49558
Customer49558
Super
6 August, 2019
Manuel Grundner [DevExpress MVP]
Manuel Grundner [DevExpress MVP]

Awesome feature! Did a lot of magic in the past to provide this feature on my own, but never that elegant!

Feedback: The naming of the event arguments is a little bit weird, e.GetSuggestions can be e.Suggestions (or e.FetchSuggestions, e.QuerySuggestions, e.SuggestionsTask...)  but I can live with that :D

6 August, 2019
Stas (DevExpress Support)
Stas (DevExpress Support)

@Manuel

We are now in the process of making all related APIs more useful and user-friendly. So, your feedback is highly appreciated.

Looking ahead, I'd like to let you know that this change as well as some other enhancements will be available in our upcoming WinForms Early Access Preview build.

7 August, 2019
rami jazbeh
rami jazbeh
Very nice
Great new feature
7 August, 2019
Alexander Krakhotko (Xafari team)
Alexander Krakhotko (Xafari team)

Great! 
Will it be available in XAF?

7 August, 2019
jerome crevecoeur
jerome crevecoeur

Hi,

is it available with multicheck items ?

Actually we have to make a custom control for search item in a multicheck Combo


7 August, 2019
Jean-Francois
Jean-Francois

Hi, 

Great feature! 

Can we define a template to render the list of suggestions? (so not just as a single line of text) 

Even more importantly in our usage scenario will it be possible to define groupings (multiple sections of results with the header of each section a not selectable item)? 

If the query is returning only e.g. top 20 results matching but also total count, will there be a way to notify the user?


7 August, 2019
Dmitry (DevExpress)
Dmitry (DevExpress)

@Jerome

No, currently you cannot use multicheck items with AutoSuggest. However, we will investigate this use case and may support it in future updates - thank you for pointing out this scenario.


@Jean-Francois

Sure, use the GridLookUpEdit control with a TileView - its tile groups allow you to categorize found lookup items. As for the 2nd question - do you mean you want to notify users that "N out of X records match the search"? Or "N records found, showing first Z records"? Both options are possible, but implementation details may vary. In any case, should you have any difficulties, feel free to ask our support engineers for assistance.

8 August, 2019
Han sangsun
Han sangsun
Hi,

I've been waiting for this feature.
Can I apply Korean language?
9 August, 2019
Svetlana (DevExpress Support)
Svetlana (DevExpress Support)

@Han sangsun

This feature does not directly depend on an input language.
As a Universal subscriber, you have a privilege to try this functionality even before the official release in the scope of our Early Access Preview version. We are planning to release it this month. Look for our blogs and announcements. 
If you face any shortcomings with the feature, do not hesitate to submit a ticket to our Support Center

9 August, 2019
Anton Plotnikov
Anton Plotnikov

Hello.

Nice feature. Will it be available for WPF?

9 August, 2019
Lex (DevExpress)
Lex (DevExpress)

@Anton

It is already here! WPF - AutoSuggest Editor (v19.1)

12 August, 2019

Please login or register to post comments.