Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

AsyncItemsSourceProvider Class

A data provider that supplies suggestions for the AutoCompleteEdit in async mode.

Namespace: DevExpress.Maui.Editors

Assembly: DevExpress.Maui.Editors.dll

NuGet Package: DevExpress.Maui.Editors

#Declaration

C#
public class AsyncItemsSourceProvider :
    ItemsSourceProviderBase

#Remarks

Follow the steps below to supply items to the editor in asynchronous mode:

  • Attach the AsyncItemsSourceProvider to the editor and handle its ItemsRequested event.
  • Use the RequestAsync or Request event argument to specify the method that returns items. The provider assigns the returned collection to the ItemsSource property.
  • Use the Text event argument to obtain the text entered in the edit box and pass it to the specified method.

You can also specify the following options:

  • RequestDelay – the time that should elapse after the text is changed and the request is called. Use this parameter to reduce the number of requests as a user types.
  • CharacterCountThreshold – the number of entered characters after which the provider starts to make requests. For example, the provider can make requests only if a user enters at least three characters.

The provider cancels the previous request if a new request is submitted. You can use the CancellationToken event argument to cancel the previous request.

<dxe:AutoCompleteEdit.ItemsSourceProvider>
    <dxe:AsyncItemsSourceProvider
        CharacterCountThreshold="1"
        RequestDelay="500"
        ItemsRequested="OnAsyncItemsSourceProviderItemsRequested"/>
</dxe:AutoCompleteEdit.ItemsSourceProvider>
void OnAsyncItemsSourceProviderItemsRequested(object sender, ItemsRequestEventArgs e) {
    e.RequestAsync = async () => await Task.Delay(3000).ContinueWith(task => this.employees.Where(employee => employee.FullName.Contains(e.Text)));
}

#Examples

#Populate an AutoCompleteEdit with Items

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 ItemsRequested="OnDelegateRequested" />
    </dxe:AutoCompleteEdit.ItemsSourceProvider>
</dxe:AutoCompleteEdit>
using System.Collections.Generic;
using System.ComponentModel;
using Microsoft.Maui.Controls;

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, ItemsRequestEventArgs e) {
            e.Request = () => {
                return States.Where(i => i.StartsWith(e.Text, StringComparison.CurrentCultureIgnoreCase)).ToList();
            };
        }
    }
}

#Populate an AutoCompleteColumn with Items

The example below uses the AsyncItemsSourceProvider to supply items for the AutoCompleteColumn:

<dxg:DataGridView ItemsSource="{Binding Path=Employees}">
    <dxg:DataGridView.Columns>
        <dxg:AutoCompleteColumn FieldName="JobTitle">
            <dxg:AutoCompleteColumn.ItemsSourceProvider>
                <dxe:AsyncItemsSourceProvider ItemsRequested="ItemsRequested"
                                              RequestDelay="500"
                                              CharacterCountThreshold="2"/>
            </dxg:AutoCompleteColumn.ItemsSourceProvider>                
        </dxg:AutoCompleteColumn>
    </dxg:DataGridView.Columns>
</dxg:DataGridView>
using System.Collections.Generic;
using System.ComponentModel;
using Microsoft.Maui.Controls;

namespace DemoCenter.Forms.Views {
    public partial class FirstLookView : ContentPage {
        public FirstLookView() {
            InitializeComponent();
            BindingContext = new EmployeesRepository();
        }

        private void ItemsRequested(object sender, ItemsRequestEventArgs 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; }
    }
}

#Inheritance

System.Object
See Also