maui-devexpress-dot-maui-dot-datagrid-1e098cce.md
A grid column used to display and edit text values. The column suggests values as a user types in a cell.
Namespace : DevExpress.Maui.DataGrid
Assembly : DevExpress.Maui.DataGrid.dll
NuGet Package : DevExpress.Maui.DataGrid
public class AutoCompleteColumn :
TextColumnBase
The AutoCompleteColumn is a text column in the DataGridView that suggests values as a user types in a cell.
To populate the collection of suggestions, use one of the following data providers:
Use the ItemsSourceProvider property to assign a data provider to the editor.
When suggestions are loaded, the editor displays them in the drop-down list. After a suggestion is selected, it is displayed in the cell. The NoResultsFoundText property specifies the text displayed in the drop-down list if no suggestions are found.
Attach the AsyncItemsSourceProvider to the column and handle its ItemsRequested event. Use the Request event argument to specify the method that returns suggestions. To get the text entered in the cell 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 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; }
}
}
The FilteredItemsSourceProvider filters an existing collection based on filter settings. Use the ItemsSource property to specify the collection of suggestions. The following properties specify how the provider searches for suggestions in the collection:
Tip
You can also use the ComboBoxColumn with the IsEditorFilterEnabled option enabled to allow users to select values from a filtered list in the drop-down.
The example below uses the FilteredItemsSourceProvider to supply suggestions for the AutoCompleteColumn.
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:dxe="clr-namespace:DevExpress.Maui.Editors;assembly=DevExpress.Maui.Editors"
xmlns:dxg="clr-namespace:DevExpress.Maui.DataGrid;assembly=DevExpress.Maui.DataGrid"
xmlns:scg="clr-namespace:System.Collections.Generic;assembly=netstandard">
<ContentPage.Content>
<dxg:DataGridView ItemsSource="{Binding Path=Employees}">
<dxg:DataGridView.Columns>
<dxg:AutoCompleteColumn FieldName="JobTitle">
<dxg:AutoCompleteColumn.ItemsSourceProvider>
<dxe:FilteredItemsSourceProvider FilterCondition="Contains"
FilterComparisonType="CurrentCultureIgnoreCase">
<dxe:FilteredItemsSourceProvider.ItemsSource>
<scg:List x:TypeArguments="x:String">
<x:String>Chief Executive Officer</x:String>
<x:String>Network Administrator</x:String>
</scg:List>
</dxe:FilteredItemsSourceProvider.ItemsSource>
</dxe:FilteredItemsSourceProvider>
</dxg:AutoCompleteColumn.ItemsSourceProvider>
</dxg:AutoCompleteColumn>
</dxg:DataGridView.Columns>
</dxg:DataGridView>
</ContentPage.Content>
</ContentPage>
Use the following properties to adjust column settings:
You can configure the following options related to all types of grid columns:
Use the following properties to sort and group data in the grid, and calculate cell values based on expressions:
The grid stores columns in the DataGridView.Columns collection. Depending on the AutoGenerateColumnsMode option, the grid automatically generates columns based on the bound data source, or you can add columns to the grid and associate them with data fields manually. See the following help topic for an example: Create Columns for Different Data Types.
This example shows how to create grid columns that display and allow users to edit data of different types (text, numbers, dates and Boolean values). The specified collection contains columns bound to the data source fields (Product.Name, Product.UnitPrice, Quantity, Date and Shipped), and one unbound column (Total) that displays data values calculated based on the values of other columns.
<dxg:DataGridView x:Name="grid" ItemsSource="{Binding Orders}" SortMode="Multiple">
<dxg:DataGridView.Columns>
<dxg:TextColumn FieldName="Product.Name" Caption = "Product" Width = "150"
SortOrder = "Descending" SortIndex = "0"/>
<dxg:NumberColumn FieldName="Product.UnitPrice" Caption = "Price" DisplayFormat="C0"/>
<dxg:NumberColumn FieldName="Quantity"
SortOrder = "Ascending" SortIndex = "1"/>
<dxg:NumberColumn FieldName="Total"
UnboundType="Integer" UnboundExpression="[Quantity] * [Product.UnitPrice]"
DisplayFormat="C0" IsReadOnly="True"/>
<dxg:DateColumn FieldName="Date" DisplayFormat="d"
IsGrouped = "true" GroupInterval = "Date"/>
<dxg:CheckBoxColumn FieldName="Shipped" AllowSort = "False"/>
</dxg:DataGridView.Columns>
</dxg:DataGridView>
System.Object BindableObject GridColumn TextColumnBase AutoCompleteColumn
YieldIfNotNull<AutoCompleteColumn>()
See Also