Articles in this section
Category / Section

How to format column using binding in MAUI DataGrid?

2 mins read

The column can be formatted by using StringFormat in the DisplayBinding.

XAML
You can utilize the String format property within the binding to format the column.

<dataGrid:SfDataGrid  x:Name="dataGrid"
                    ColumnWidthMode="Auto" 
                    GridLinesVisibility="Both" 
                    HeaderGridLinesVisibility="Both"
                    ItemsSource="{Binding Employees}">
    <dataGrid:SfDataGrid.Columns>
        <dataGrid:DataGridNumericColumn MappingName="EmployeeID" HeaderText="Employee ID"/>
        <dataGrid:DataGridTextColumn MappingName="Name" />
        <dataGrid:DataGridNumericColumn MappingName="Salary" 
                                    HeaderText="Salary"
                                    DisplayBinding="{Binding Path=Salary,StringFormat='{}{0:C}'}"/>
    </dataGrid:SfDataGrid.Columns>
</dataGrid:SfDataGrid>

C#

public MainPage()
{
    InitializeComponent();

    //Equivalent to the code in the XAMl section

    DataGridTextColumn salaryColumn = new DataGridTextColumn() { MappingName = "Salary", HeaderText = "Salary" };
    salaryColumn.DisplayBinding = new Binding() { Path = "Salary", StringFormat = "{0:C}" };
    dataGrid.Columns.Add(salaryColumn);
}

The following screenshot shows how to format a column using binding in the MAUI DataGrid.

SfDataGrid_Column_Formatted_using_Binding.png

Download the complete sample from GitHub

Conclusion
I hope you enjoyed learning how to format columns using binding in the .NET MAUI DataGrid.

You can refer to our .NET MAUI DataGrid feature tour page to learn about its other groundbreaking feature representations. Explore our .NET MAUI DataGrid Documentation to understand how to present and manipulate data.
For current customers, check out our .NET MAUI components from the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to check out our .NET MAUI DataGrid and other .NET MAUI components.
Please let us know in the comments section if you have any queries or require clarification. You can also contact us through our support forums, Direct-Trac or 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