Getting Started with .NET MAUI DataGrid
10 Jul 20269 minutes to read
This section provides a quick overview for working with the SfDataGrid for .NET MAUI. Follow the steps below to add a basic DataGrid to your project.
To quickly get started with the .NET MAUI DataGrid, watch this video:
Prerequisites
Before proceeding, ensure the following are set up:
- Install .NET 9 SDK or later.
- Set up a .NET MAUI environment with Visual Studio 2022 v17.12 or later.
Step 1: Create a new .NET MAUI project
- Go to File > New > Project and choose the .NET MAUI App template.
- Name the project and choose a location. Then, click Next.
- Select the .NET framework version and click Create.
Step 2: Install the Syncfusion® MAUI DataGrid NuGet package
- In Solution Explorer, right-click the project and choose Manage NuGet Packages.
- Search for Syncfusion.Maui.DataGrid and install the latest version.
- Ensure the necessary dependencies are installed correctly, and the project is restored.
Prerequisites
Before proceeding, ensure the following are set up:
- Install .NET 9 SDK or later.
- Set up a .NET MAUI environment with Visual Studio Code.
- Ensure that the .NET MAUI workloads are installed and configured as described here.
Step 1: Create a new .NET MAUI project
- Open the command palette by pressing
Ctrl+Shift+Pand type .NET:New Project and enter. - Choose the .NET MAUI App template.
- Select the project location, type the project name and press Enter.
- Then choose Create project.
Step 2: Install the Syncfusion® MAUI DataGrid NuGet package
- Press Ctrl + ` (backtick) to open the integrated terminal in Visual Studio Code.
- Ensure you’re in the project root directory where your .csproj file is located.
- Run the command
dotnet add package Syncfusion.Maui.DataGridto install the Syncfusion® .NET MAUI DataGrid package. - To ensure all dependencies are installed, run
dotnet restore.
Prerequisites
Before proceeding, ensure the following are set up:
- Install .NET 9 SDK or later.
- Set up a .NET MAUI environment with JetBrains Rider 2024.3 or later.
- Make sure the MAUI workloads are installed and configured as described here.
Step 1: Create a new .NET MAUI project
- Go to File > New Solution, Select .NET (C#) and choose the .NET MAUI App template.
- Enter the Project Name, Solution Name, and Location.
- Select the .NET framework version and click Create.
Step 2: Install the Syncfusion® MAUI DataGrid NuGet package
- In Solution Explorer, right-click the project and choose Manage NuGet Packages.
- Search for Syncfusion.Maui.DataGrid and install the latest version.
- Ensure the necessary dependencies are installed correctly, and the project is restored. If not, Open the Terminal in Rider and manually run:
dotnet restore
Step 3: Register Syncfusion handler
To use Syncfusion controls, you must register the Syncfusion core handler in your application’s startup configuration.
In the MauiProgram.cs file (located at the root of your project), add the namespace and register the handler in the CreateMauiApp method:
using Syncfusion.Maui.Core.Hosting;Register the Syncfusion core handler in your CreateMauiApp method of MauiProgram.cs file to use Syncfusion controls.
builder.ConfigureSyncfusionCore();Step 4: Define Model and View Model
Create a simple data model as shown in the following code example, and save it as OrderInfo.cs file:
public class OrderInfo
{
private string? orderID;
private string? customerID;
private string? customer;
private string? shipCity;
private string? shipCountry;
public string? OrderID
{
get { return orderID; }
set { this.orderID = value; }
}
public string? CustomerID
{
get { return customerID; }
set { this.customerID = value; }
}
public string? ShipCountry
{
get { return shipCountry; }
set { this.shipCountry = value; }
}
public string? Customer
{
get { return this.customer; }
set { this.customer = value; }
}
public string? ShipCity
{
get { return shipCity; }
set { this.shipCity = value; }
}
public OrderInfo(string orderId, string customerId, string country, string customer, string shipCity)
{
this.OrderID = orderId;
this.CustomerID = customerId;
this.Customer = customer;
this.ShipCountry = country;
this.ShipCity = shipCity;
}
}Note: If you want your data model to respond to property changes, implement the
INotifyPropertyChangedinterface in your model class. This enables the DataGrid to refresh automatically when data properties are updated.
Next, create a data repository class that manages a collection of OrderInfo objects. This repository serves as a simple data source for the DataGrid. Create a new class file and save it as OrderInfoRepository.cs in the same Models folder or project root:
public class OrderInfoRepository
{
private ObservableCollection<OrderInfo> orderInfo;
public ObservableCollection<OrderInfo> OrderInfoCollection
{
get { return orderInfo; }
set { this.orderInfo = value; }
}
public OrderInfoRepository()
{
orderInfo = new ObservableCollection<OrderInfo>();
this.GenerateOrders();
}
public void GenerateOrders()
{
orderInfo.Add(new OrderInfo("1001", "Maria Anders", "Germany", "ALFKI", "Berlin"));
orderInfo.Add(new OrderInfo("1002", "Ana Trujillo", "Mexico", "ANATR", "Mexico D.F."));
orderInfo.Add(new OrderInfo("1003", "Ant Fuller", "Mexico", "ANTON", "Mexico D.F."));
orderInfo.Add(new OrderInfo("1004", "Thomas Hardy", "UK", "AROUT", "London"));
orderInfo.Add(new OrderInfo("1005", "Tim Adams", "Sweden", "BERGS", "London"));
orderInfo.Add(new OrderInfo("1006", "Hanna Moos", "Germany", "BLAUS", "Mannheim"));
orderInfo.Add(new OrderInfo("1007", "Andrew Fuller", "France", "BLONP", "Strasbourg"));
orderInfo.Add(new OrderInfo("1008", "Martin King", "Spain", "BOLID", "Madrid"));
orderInfo.Add(new OrderInfo("1009", "Lenny Lin", "France", "BONAP", "Marsiella"));
}
}Step 5: Import the DataGrid namespace
Add the following namespace in your XAML or C#.
xmlns:syncfusion="clr-namespace:Syncfusion.Maui.DataGrid;assembly=Syncfusion.Maui.DataGrid"using Syncfusion.Maui.DataGrid;Step 6: Add the DataGrid component
Create a ViewModel instance and set it as the DataGrid’s BindingContext. This enables property binding from ViewModel class.
To populate the SfDataGrid, bind the item collection from its BindingContext to SfDataGrid.ItemsSource property.
The following code example binds the collection created in the previous step to the SfDataGrid.ItemsSource property:
<syncfusion:SfDataGrid x:Name="dataGrid"
ItemsSource="{Binding OrderInfoCollection}">
<syncfusion:SfDataGrid.BindingContext>
<local:OrderInfoRepository />
</syncfusion:SfDataGrid.BindingContext>
</syncfusion:SfDataGrid>OrderInfoRepository viewModel = new OrderInfoRepository();
SfDataGrid dataGrid = new SfDataGrid();
dataGrid.ItemsSource = viewModel.OrderInfoCollection;The following screenshot shows the DataGrid populated with sample data:

You can download the DataGrid Getting Started sample from GitHub.
Note: You can refer to our .NET MAUI DataGrid feature tour page for its groundbreaking feature representations. You can also explore our .NET MAUI DataGrid Example that shows you how to render the DataGrid in .NET MAUI.