.NET MAUI DataGrid Events
The Telerik UI for .NET MAUI DataGrid component exposes a set of events which help users achieve seamless and effective experience when interacting with the component.
Loading Content on Demand
The load-on-demand feature gets implemented through the LoadOnDemand event. The LoadOnDemand event handler receives the following parameters:
- The
senderargument, which is of typeobject, but can be cast to theRadDataGridtype. - A
LoadOnDemandEventArgsobject, which provides theIsDataLoaded(bool) property, indicating whether the data is loaded.
For more information, see the topic about loading data on demand in the .NET MAUI DataGrid.
The following example demonstrates how to use the LoadOnDemand event.
1. Define the LoadOnDemand method in XAML.
<telerik:RadDataGrid x:Name="dataGrid"
ItemsSource="{Binding Items}"
LoadOnDemand="dataGrid_LoadOnDemand"
LoadOnDemandMode="Automatic"
LoadOnDemandBufferItemsCount="{Binding Source={x:Reference slider}, Path=Value}"/>
2. Create the method that defines the functionality of the event.
private void dataGrid_LoadOnDemand(object sender, Telerik.Maui.Controls.DataGrid.LoadOnDemandEventArgs e)
{
for (int i = 0; i < 15; i++)
{
((sender as RadDataGrid).ItemsSource as ObservableCollection<Person>).Add(new Person() { Name = "Person " + i, Age = i + 18, Gender = i % 2 == 0 ? Gender.Male : Gender.Female });
}
e.IsDataLoaded = true;
}
Loading Distinct Values
The DataGrid enables you to load the distinct values that will be displayed in the Telerik.Maui.Controls.DataGrid.DataGridDistinctValuesFilterView through the DistinctValuesLoading event. The DistinctValuesLoading event handler receives the following parameters:
- The
senderargument, which is of typeobject, but can be cast to theRadDataGridtype. - A
DistinctValuesLoadingEventArgsobject, which provides the following properties:DistinctValues—Specifies a list of values of typeIEnumerablewhich are to be displayed in theDataGridDistinctValuesFilterView.- (Read-only)
Columnof typeDataGridColumn—Gets the column for which the distinct values are being loaded.
For more information, see the topic about the available filtering options in the .NET MAUI DataGrid.
Binding to Data
The DataGrid also provides the DataBindingComplete event which occurs when the associated DataGrid ItemsSource has been successfully bound to the control, or when any data operation like grouping, sorting, or filtering is applied. The DataBindingComplete event handler receives the following parameters:
- The
senderargument, which is of typeobject, but can be cast to theRadDataGridtype. - A
DataBindingCompleteEventArgsobject, which provides theDataView(IDataViewCollection) property and allows for traversing and/or manipulating the already computed data view.
Modifying the Selection
The DataGrid delivers the SelectionChanged event which is triggered whenever the SelectedItems collection is changed. The SelectionChanged event handler receives the following parameters:
- The
senderargument, which is of typeobject, but can be cast to theRadDataGridtype. - A
DataGridSelectionChangedEventArgsobject, which provides the following properties:RemovedItems—Gets a list of the removed items from theSelectedItemscollection.AddedItems—Gets a list of the added items to theSelectedItemscollection.
For more information, see the article about the SelectionChanged event of the .NET MAUI DataGrid.
Changing the Current Cell
The DataGrid also supports the CurrentCellChanged event which is invoked when the current cell changes. The CurrentCellChanged event handler receives the following parameters:
- The
senderargument, which is of typeobject, but can be cast to theRadDataGridtype. - A
CurrentCellChangedEventArgsobject, which provides the following properties:OldCurrentCell—Gets the previouslyCurrentCell.NewCurrentCell—Gets the newCurrentCell.
For more information, see the article about the CurrentCellChanged event in the .NET MAUI DataGrid.
Reordering the Column
The DataGrid exposes the ColumnReorderStarting, ColumnReordering, ColumnReorderCompleting, and ColumnReordered events related to the column reordering operation. For more details, review the DataGrid Columns Reordering article.
Resizing the Column
The DataGrid resizing feature exposes a ColumnUserResizeCompleted event which is invoked when a column is resized by user interaction. The ColumnUserResizeCompleted event handler receives the following parameters:
- The
senderargument, which is of typeobject, but can be cast to theRadDataGridtype. - A
ColumnUserResizeCompletedEventArgsobject, which provides the following properties:Column(DataGridColumn)—Gets the previouslyCurrentCell.Width(double)—Gets the width of the column that is resized.
Additional Resources
- .NET MAUI DataGrid Product Page
- .NET MAUI DataGrid Forum Page
- Telerik .NET MAUI Blogs
- Telerik .NET MAUI Roadmap