WinForms Lookup Editors - AutoSearch Mode

WinForms Team Blog
14 August 2019

In the previous post, I announced our new AutoSuggest mode for both the DevExpress LookUpEdit and GridLookUpEdit controls. Briefly, AutoSuggest allows the editor to execute a custom Task to retrieve drop-down menu items (as such, the editor has a virtual data source that changes each time a user enters values within the lookup’s text box). We expect that most of you will use this new feature for empty, unbound editors. If your lookup editor is bound to a static data source, source records will be displayed in only one use case: when the text box is empty and a user presses the drop-down button.

A few weeks ago, this was the only use case we considered while developing AutoSuggest. Thanks to some great feedback, we decided to extend our implementation and to address another important usage scenario: filtering records in bound editors.

Until now, if you wanted users to search for lookup records, you were forced to use our SearchLookUpEdit. This editor addressed the business requirement, but it lacked some of the modern features today’s users have come to expect from advanced desktop apps. SearchLookUpEdit shipped with a ”locked” text box that did not allow users to enter text values via the keyboard. To locate records, it activated a drop-down panel and allowed users to enter search criteria within its embedded find panel.

With v19.2, you will be able to bind a LookUpEdit \ GridLookUpEdit editor to a data source, change the Properties.SearchMode to AutoSearch and voila: give users the ability to enter search values within the editor’s text box - matching records will be automatically displayed within the lookup’s drop-down menu.

Whenever we implement a new feature, we do everything possible to extend core functionality across multiple products. For instance, this new AutoSearch feature will accept the same syntax used by our Find Panel.

Just like AutoSuggest, AutoSearch fires its own event when users enters text values (the AutoSearch event). Though you do not need to handle the event (everything will work out-of-the-box), we’ve given you the ability to do so when needs arise. For example, you can use the e.SetParameters method in the event handler to fine-tune search results. This method accepts two parameters that are similar to ParserKind and Condition properties used by Find Panels displayed within our WinForms data-aware controls:

1
2
3
4
5
6
using DevExpress.Data.Filtering;

private void LookUpEdit1_AutoSearch(object sender, LookUpEditAutoSearchEventArgs e)
{
e.SetParameters(FindPanelParserKind.And, FilterCondition.StartsWith);
}

Since arguments for both AutoSuggest and AutoSearch events derive from the same base class, our custom highlight API applies. The example below illustrates how to highlight an entire data field value when it matches the value entered within the text box.

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
private void LookUpEdit1_AutoSearch(object sender, LookUpEditAutoSearchEventArgs e)
{
e.SetParameters(FindPanelParserKind.And, FilterCondition.StartsWith);
e.SetHighlightRanges(CustomHightlight(e.Text));
}

static Func<string, string, DisplayTextHighlightRange[]> CustomHightlight(string userText)
{
return (displayText, fieldName) =>
{
if (fieldName == "ShipCity" || fieldName == "ShipCountry")
{
if (displayText.StartsWith(userText))
return new DisplayTextHighlightRange[] {
new DisplayTextHighlightRange(0, displayText.Length) };
}
return null;
};
}

Your Feedback Matters

Though our SearchLookUpEdit will continue to be used for our server mode data sources (AutoSearch will not support server mode) - AutoSearch should address all remaining usage scenarios. Please let me know what you think of this new feature and how likely you are to use it in your next WinForms project.

12 comment(s)
Thorsten Sommer
Thorsten Sommer
Thank you very much for this nice addition. I will certainly use it.
14 August, 2019
Santiago Moscoso
Santiago Moscoso

Excellent.

We totally need this on our XAF applications, specially on the Filter Row. 

14 August, 2019
Ricardo R. Araoz
Ricardo R. Araoz
Thank you for all the work you put into your controls.  This is a great feature and I will definitely use it!
14 August, 2019
Christopher Jay
Christopher Jay
Very nice, thank you!
14 August, 2019
Stepan Lauryn
Stepan Lauryn
How is it with Case-Insenzitiv search? I use MS SQL Server and have db collation Case Sensitiv. User would like to search Case-Insenzitiv. Is it posible?


14 August, 2019
Dmitry (DevExpress)
Dmitry (DevExpress)

@Stepan Lauryn

Currently the search is always case-insensitive. We'll carefully study user feedback once the EAP installation is available, and may add an additional parameter for the "SetParameters" method that will allow you to choose the desired behavior.

15 August, 2019
Manuel Grundner [DevExpress MVP]
Manuel Grundner [DevExpress MVP]
That is absolutly awesome! :) Great job!
15 August, 2019
Rubén Duarte
Rubén Duarte
Is this functionallity will working on XAF too ? 
15 August, 2019
Benjamin Hofmann
Benjamin Hofmann
Great Feature! And a good reason to upgrade when 19.2 is out.
15 August, 2019
Noufal Aboobacker 1
Noufal Aboobacker 1
We require similar feature in WPF as well in 19.2 please. It’s not fair 😞
22 August, 2019
Andre Francis
Andre Francis
Can someone confirm if users can "add" values to the list. So if a user types something NOT in the list, will the input be accepted and get added to the list for future searches?
27 August, 2019
Svetlana (DevExpress Support)
Svetlana (DevExpress Support)

@Andre Francis

To add new values to a data source, you need to handle the LookUpEdit.ProcessNewValue event. Add a new record to your data source and set the e.Handled property to true in the event handler. 

If you have further questions, feel free to submit a new ticket to our Support Center to discuss your task further.

28 August, 2019

Please login or register to post comments.