New to Telerik UI for .NET MAUI? Start a free 30-day trial

.NET MAUI DataGrid Current Cell

The Telerik UI for .NET MAUI DataGrid provides options for configuring the behavior and style of its current cell.

Setting the Behavior

The DataGrid allows you to use the CurrentCell property of type DataGridCellInfo to programmatically modify the current cell during keyboard navigation, when using the mouse, and so on.

The DataGrid also supports the CurrentCellChanged event which is invoked when the current cell changes as a result of user interaction with the keyboard.

The CurrentCellChanged event handler receives the following parameters:

  • The sender argument, which is of type object, but can be cast to the RadDataGrid type.
  • A CurrentCellChangedEventArgs object, which provides the following properties:
    • OldCurrentCell—Gets the previous CurrentCell.
    • NewCurrentCell—Gets the new CurrentCell.

Styling the Cell

You can also style the current DataGrid cell by using the CurrentCellStyle of type DataGridBorderStyle and applying the BackgroundColor, BorderColor, and BorderThickness properties.

Example

The following example shows the full implementation of the configurations for the current DataGrid cell.

1. Set the ViewModel.

2. Set the Business object.

3. Provide the DataGrid definition in XAML.

<telerik:RadDataGrid x:Name="dataGrid" 
                     Grid.Row="1"
                     ItemsSource="{Binding People}"
                     CurrentCellChanged="dataGrid_CurrentCellChanged"
                     CurrentCell="{Binding Cell, Mode=TwoWay}"
                     CurrentCellStyle="{StaticResource CurrentCellStyle}"/>

4. Set the style for the CurrentCellStyle that is defined in the page resources.

<telerik:DataGridBorderStyle x:Key="CurrentCellStyle"
                             BorderColor="Black"
                             BackgroundColor="LightGray"
                             BorderThickness="2"/>

5. Set the CurrentCellChanged event.

private void dataGrid_CurrentCellChanged(object sender, CurrentCellChangedEventArgs e)
{
    var data = e.NewCurrentCell;
    this.cellInfo.Text = data.Value.ToString();
}

The following image shows the end result.

DataGrid Current Cell

Additional Resources

See Also

In this article