Articles in this section
Category / Section

How to begin editing a cell on button click in .NET MAUI DataGrid?

3 mins read

This article demonstrates how to begin editing a cell on button click in .NET MAUI DataGrid (SfDataGrid).

You can programmatically edit a cell by calling the SfDataGrid.BeginEdit method. This method puts the specified cell into edit mode, allowing data to be modified programmatically. It selects the corresponding cell and initiates edit mode.

Xaml
<ContentPage.Content>
        <Grid RowDefinitions="Auto,*">
            <HorizontalStackLayout Grid.Row="0" Spacing="10" Margin="10">
                <Button Text="Begin Edit" Clicked="OnBeginEditClicked" />
            </HorizontalStackLayout>

            <syncfusion:SfDataGrid Grid.Row="1"
                x:Name="dataGrid"
                AllowEditing="True"
                SelectionUnit="Cell"
                SelectionMode="Single"                  
                ItemsSource="{Binding OrderInfoCollection}">
                
                <syncfusion:SfDataGrid.Columns>
                    <syncfusion:DataGridNumericColumn HeaderText="Order ID" Format="0"
                    MappingName="OrderID" Width="150"/>
                    <syncfusion:DataGridTextColumn HeaderText="Customer ID"
                    MappingName="CustomerID"
                    Width="150" />
                    <syncfusion:DataGridTextColumn HeaderText="Ship Country"
                    MappingName="ShipCountry"
                    Width="150" />
                </syncfusion:SfDataGrid.Columns>
                
            </syncfusion:SfDataGrid>
        </Grid>
</ContentPage.Content>
Xaml.cs
public partial class MainPage : ContentPage
{
    public MainPage()
    {
        InitializeComponent();
    }

    private void OnBeginEditClicked(object sender, EventArgs e)
    {
         dataGrid.BeginEdit(1,1); 
    }
}

You can download this example on GitHub.

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied