We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to edit a column in SfDataGrid?

Currently SfDataGrid does not directly support editing of GridCells. However if your requirement is to edit the text of the GridCells during runtime, SfDataGrid allows you to achieve this by creating a TemplateColumn and loading an Entry cell into it using the DataTemplate property. The edited values are automatically committed since Entry cell has a default two way binding.

Refer the following code example to edit the text of GridCell in runtime.

<?xml version="1.0" encoding="utf-8" ?>

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"

             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"

             xmlns:sfgrid="clr-namespace:Syncfusion.SfDataGrid.XForms;

                                                assembly=Syncfusion.SfDataGrid.XForms"

             xmlns:local ="clr-namespace:Edit;assembly=Edit">

            

  <ContentPage.BindingContext>

   <local:ViewModel x:Name="viewModel" />

  </ContentPage.BindingContext>

 

  <sfgrid:SfDataGrid x:Name="dataGrid"

                     ColumnSizer="Star"

                     ItemsSource="{Binding Info}">

 

   <sfgrid:SfDataGrid.Columns x:TypeArguments="sfgrid:Columns">

    

     <sfgrid:GridTextColumn MappingName="ID"/>

    

     //Creation of template column

     <sfgrid:GridTemplateColumn MappingName="Name">

        <sfgrid:GridTemplateColumn.CellTemplate>

         <DataTemplate>

           <Entry x:Name="label" Text="{Binding Name}" TextColor="Black"

                   HorizontalOptions="Center" VerticalOptions="Center" />

         </DataTemplate>

        </sfgrid:GridTemplateColumn.CellTemplate>

     </sfgrid:GridTemplateColumn>

 

   <sfgrid:GridTextColumn MappingName="Percentage"/>

     <sfgrid:GridTextColumn MappingName="Result"/>

     <sfgrid:GridTextColumn MappingName="Remarks"/>

 

   </sfgrid:SfDataGrid.Columns>

   </sfgrid:SfDataGrid>

</ContentPage>

 

The following screenshots shows the final outcome when the above code is executed.

You can download the working sample for this KB from the below link.

http://www.syncfusion.com/downloads/support/directtrac/general/ze/Editing-1248654463

Article ID: Published Date: Last Revised Date: Platform: Control:
6227 02/08/2016 12/15/2016 Xamarin.Forms SfDataGrid
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.