Skip to content

SyncfusionExamples/How-to-restrict-decimal-input-during-editing-in-.NET-MAUI-DataGrid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

How to restrict decimal input during editing in .NET MAUI DataGrid

This sample shows how to restrict decimal input in a Syncfusion .NET MAUI SfDataGrid numeric column so it accepts only whole numbers and completely blocks decimal input. Using this approach, users cannot type a decimal point and values remain integers while editing the numeric column.

You can achieve this by replacing the default numeric cell renderer and applying an integer-only edit mask to the underlying SfNumericEntry during edit mode. That means, set SfNumericEntry's CustomFormat as "$00000". So decimals are blocked at the input level in numeric cell. You can also keep the column's display format as "0" for consistent integer formatting.


    public class CustomTextRenderer : DataGridNumericCellRenderer
    {
        public override void OnInitializeEditView(DataColumnBase dataColumn, SfNumericEntry view)
        {
            base.OnInitializeEditView(dataColumn, view);

            if (view != null && view is SfNumericEntry entry)
            {
                var value = dataColumn.CellValue;

                if (dataColumn != null && dataColumn.DataGridColumn != null && dataColumn.DataGridColumn.MappingName == "Qty")
                {
                    entry.CustomFormat = "$00000";
                }
            }
        }

    }

About

This demo shows how to restrict decimal input during editing in numeric column in .NET MAUI DataGrid

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages