Winforms interface development tips Secret! DevExpress automatic suggestions

Under load the full version of DevExpress v19.2

DevExpress Winforms Controls  built more than 140 UI controls and libraries, build perfect and smooth, beautiful and easy to use application. In this article, small series will introduce some of the features WinForms Lookup Editors control, and how to select the appropriate WinForms WinForms look for the next project.

Published v19.2 version will LookUpEdit and GridLookupEdit control (auto-suggestion) includes a great new feature. Before explaining this new functionality, which will now be automatically separated from the conventional mode field may be used to enable the component attribute SearchMode autocomplete. When active, auto-complete feature forces binding the query editor to find records matching the text entered by the user, and displays the first item it finds in the query:

DevExpress Winforms tutorial tips

To activate the automatic suggestion, you need to set SearchMode AutoSuggest. And the AutoComplete (hidden in the lookup record does not match the data binding) a different, dynamically changing the AutoSuggest editor data source when the user inputs text (so that it can be completely empty, used with unbound editor) .

Each time a user enters a new character, the editor will look AutoSuggest trigger event. We must handle this event and assign a custom System.Threading.Tasks.Task objects. This asynchronous cancel the task must return a collection of records, these records will be considered a source editor.

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); 
}

DESCRIPTION Task is entirely up to you: In the demo, will resolve a huge Excel files stored locally. You can retrieve data from a database file, you can also send an SQL query and retrieve records from a remote server.

DevExpress Winforms tutorial tips

When looking to get the drop-down project, the editor will scan all the records and highlight portions of the text to match the user's project title. This default logic covers many simple scene, but if you want, you are free to implement custom highlighted mode.

In the demonstration, "Enter the city name" to find populated by a task, the task of searching match the city and state names. However, to find records also include country / region name. Highlight the default mode is not suitable for such a situation, because it highlights the national character in the name (Task ignore these characters).

DevExpress Winforms tutorial tips

To resolve this mismatch, the event parameters assigned to SetHighlightRanges custom methods.

void OnAutoSuggest(object sender, LookUpEditAutoSuggestEventArgs e) { 
//... 
// Set Custom Highlight Strategy
e.SetHighlightRanges(HighlightTags(e.Text)); 
}

DevExpress technical exchange group: 540 330 292 welcome into the group together to discuss

Published 348 original articles · won praise 37 · views 630 000 +

Guess you like

Origin blog.csdn.net/AABBbaby/article/details/103920710