Giter Club home page Giter Club logo

how-to-allow-user-to-add-a-new-row-in-winui-datagrid-'s Introduction

How to allow user to add a new row in WinUI DataGrid?

About the sample

This example describes how to allow user to add a new row in WinUI DataGrid.

WinUI DataGrid (SfDataGrid) provides built-in row called AddNewRow. It allows user to add a new row to underlying collection. You can enable or disable by setting SfDataGrid.AddNewRowPosition property. You can also set the position of built-in AddNewRow through AddNewRowPosition property.

When you start editing in AddNewRow, the WinUI DataGrid control creates an instance for the underlying data object and adds it to underlying collection when editing completed. So, the underlying data object must be defined with default constructor.

You can commit or cancel a new row from being added by pressing the Enter and Esc key respectively.

<syncfusion:SfDataGrid x:Name="dataGrid"
                       AddNewRowPosition="Top"
                       AllowEditing="True"
                       ItemsSource="{Binding ProductInfo}">

Shows the new row added in SfDataGrid

Note: The underlying data object must be defined with default constructor.

Add a new row programmatically to WinUI DataGrid

You can add a new row by using SfDataGrid.View.AddNew and SfDataGrid.View.CommitNew methods.

private void Button_Click(object sender, RoutedEventArgs e)
{
     this.dataGrid.View.AddNew();
     this.dataGrid.View.CommitNew();
}

Customize default string of built-in AddNewRow

WinUI DataGrid enables you to customize the watermark text of AddNewRow by changing value of AddNewRowText in Resource Designer.

You can go through this user guide to know more about customizing default string of AddNewRow’s text.

Initializing default values for AddNewRow

WinUI DataGrid allows you to set the default values for AddNewRow while initiating through AddNewRowInitiatingEventArgs.NewObject property in SfDataGrid.AddNewRowInitiating event.

dataGrid.AddNewRowInitiating += OnAddNewRowInitiating;

private void OnAddNewRowInitiating(object sender, Syncfusion.UI.Xaml.DataGrid.AddNewRowInitiatingEventArgs e)
{
     var data = e.NewObject as ProductSalesDetails;
     data.Product = "Car";
     data.Country = "UK";
     data.State = "Scotland";
     data.Quantity = 5;
     data.Discount = 12;
     data.Amount = 200000;
}

Shows the default values while AddNewRow initiating in SfDataGrid

Take a moment to peruse the WinUI DataGrid - Add new rows documentation, where you can find about add new rows with code examples.

Requirements to run the demo

Visual Studio 2019 and above versions

how-to-allow-user-to-add-a-new-row-in-winui-datagrid-'s People

Contributors

amalrajumapathyselvam avatar syncfusionbuild avatar vijayarasan avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

vijayarasan

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.