Articles in this section
Category / Section

How to Prevent Native keyboard when Editing Cells in MAUI DataGrid?

2 mins read

This article demonstrates how to prevent native keyboard when editing cells in .NET MAUI DataGrid.

In SfDataGrid, custom rendering can be used to prevent the Android native keyboard from appearing while preserving edit functionality. This is achieved by overriding the OnInitializeEditView method, where the platform-specific Android native control is accessed and its ShowSoftInputOnFocus property is set to false. This approach maintains the focus behavior for editing while explicitly instructing Android not to display the soft keyboard when the control receives focus.

C#
public MainPage()
{
    InitializeComponent();
    dataGrid.CellRenderers.Remove("Text");
    dataGrid.CellRenderers.Add("Text", new CustomTextCellRenderer());
}

public class CustomTextCellRenderer : DataGridTextBoxCellRenderer
{
    public override void OnInitializeEditView(DataColumnBase dataColumn, SfDataGridEntry view)
    {
        base.OnInitializeEditView(dataColumn, view);
#if ANDROID
        if (view != null && view is SfDataGridEntry entry && DataGrid != null)
        {
            DataGrid.Dispatcher.DispatchDelayed(TimeSpan.FromMilliseconds(100), () =>
            {
                var nativeEntry = entry.Handler?.PlatformView as Android.Widget.EditText;
                if (nativeEntry != null)
                {
                    nativeEntry.ShowSoftInputOnFocus = false;
                }
            });
        }
#endif
    }
}
Xaml
<syncfusion:SfDataGrid
        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>

You can download this example on GitHub.

Conclusion

I hope you enjoyed learning about How to prevent native keyboard when editing cells in .NET MAUI DataGrid.

You can refer to our .NET MAUI DataGrid’s feature tour page to learn about its other groundbreaking feature representations. You can also explore our .NET MAUI DataGrid Documentation to understand how to present and manipulate data. For current customers, you can check out our .NET MAUI components on the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to explore our .NET MAUI DataGrid and other .NET MAUI components.

If you have any queries or require clarifications, please let us know in the comments below. You can also contact us through our support forums,Direct-Trac or feedback portal, or the feedback portal. We are always happy to assist you!

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