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

WinForms Lookup Editors - AutoSearch Mode

$
0
0

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
usingDevExpress.Data.Filtering;

privatevoidLookUpEdit1_AutoSearch(objectsender, LookUpEditAutoSearchEventArgse)
{
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
privatevoidLookUpEdit1_AutoSearch(objectsender, LookUpEditAutoSearchEventArgse)
{
e.SetParameters(FindPanelParserKind.And, FilterCondition.StartsWith);
e.SetHighlightRanges(CustomHightlight(e.Text));
}

staticFunc<string, string, DisplayTextHighlightRange[]> CustomHightlight(stringuserText)
{
return (displayText, fieldName) =>
{
if (fieldName == "ShipCity" || fieldName == "ShipCountry")
{
if (displayText.StartsWith(userText))
returnnewDisplayTextHighlightRange[] {
newDisplayTextHighlightRange(0, displayText.Length) };
}
returnnull;
};
}

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.


Viewing all articles
Browse latest Browse all 2370

Trending Articles