mobilecontrols-devexpress-dot-xamarinforms-dot-editors-681fedb5.md
A data provider that supplies suggestions for the AutoCompleteEdit and AutoCompleteColumn in async mode.
Namespace : DevExpress.XamarinForms.Editors
Assembly : DevExpress.XamarinForms.Editors.dll
NuGet Package : DevExpress.XamarinForms.Editors
public class AsyncItemsSourceProvider :
ItemsSourceProviderBase
Attach the AsyncItemsSourceProvider to the editor and handle its SuggestionsRequested event. Use the Request event argument to specify the method that returns suggestions. The provider assigns the returned collection to the ItemsSource property. To get the text entered in the edit box and pass it to the specified method, use the Text event argument.
You can also specify the following options:
The provider cancels the previous request if a new request is submitted. You can use the CancellationToken event argument to cancel the previous request.
The example below uses the AsyncItemsSourceProvider to supply suggestions for the AutoCompleteEdit.
<dxe:AutoCompleteEdit
LabelText="State"
PlaceholderText="Type here to search..."
VerticalOptions="Center"
Margin="16,0">
<dxe:AutoCompleteEdit.ItemsSourceProvider>
<dxe:AsyncItemsSourceProvider SuggestionsRequested="OnDelegateRequested" />
</dxe:AutoCompleteEdit.ItemsSourceProvider>
</dxe:AutoCompleteEdit>
using System.Collections.Generic;
using System.ComponentModel;
using Xamarin.Forms;
namespace AutoCompleteEditExample {
public partial class MainPage : ContentPage {
public MainPage() {
InitializeComponent();
States = new List<string>();
States.AddRange(new string[] { "California", "Colorado", "Connecticut" /*...*/ });
}
public List<string> States { get; }
void OnDelegateRequested(object sender, SuggestionsRequestEventArgs e) {
e.Request = () => {
return States.Where(i => i.StartsWith(e.Text, StringComparison.CurrentCultureIgnoreCase)).ToList();
};
}
}
}
The example below uses the AsyncItemsSourceProvider to supply suggestions for the AutoCompleteColumn.
<dxg:DataGridView ItemsSource="{Binding Path=Employees}">
<dxg:DataGridView.Columns>
<dxg:AutoCompleteColumn FieldName="JobTitle">
<dxg:AutoCompleteColumn.ItemsSourceProvider>
<dxe:AsyncItemsSourceProvider SuggestionsRequested="SuggestionsRequested"
RequestDelay="500"
CharacterCountThreshold="2"/>
</dxg:AutoCompleteColumn.ItemsSourceProvider>
</dxg:AutoCompleteColumn>
</dxg:DataGridView.Columns>
</dxg:DataGridView>
using System.Collections.Generic;
using System.ComponentModel;
using Xamarin.Forms;
namespace DemoCenter.Forms.Views {
public partial class FirstLookView : ContentPage {
public FirstLookView() {
InitializeComponent();
BindingContext = new EmployeesRepository();
}
private void SuggestionsRequested(object sender, SuggestionsRequestEventArgs e) {
EmployeesRepository employeesRepository = BindingContext as EmployeesRepository;
e.Request = () => {
return employeesRepository.JobTitles.Where(i => i.StartsWith(e.Text, StringComparison.CurrentCultureIgnoreCase)).ToList();
};
}
}
public class EmployeesRepository {
public IList<Employee> Employees { get; set; }
public IList<string> JobTitles { get; set; }
}
public class Employee {
public string JobTitle { get; set; }
}
}
Object ItemsSourceProviderBase AsyncItemsSourceProvider
See Also