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. Image for the cookie policy date
close icon

GridTemplateColumn with button throw System.NullReferenceException

Hello everyone,

I'm trying to implement a SfDataGrid with a button that allows to interact with the element, but if the NavigationMode is set to Cell, everytime the button is clicked a NullReferenceException is thrown. This dosen't happen with NavigationMode=Row, but I need to be able to edit the entries, so in order to allow editing I need it to be NavigationMode=Cell.

To show the problem, I slightly changed the example "Data binding" in control Data Grid in Essential Studio
  •      In file ListViewPage.xaml:

<sync:SfDataGrid x:Name="syncgrid"




ItemsSource="{Binding OrdersListDetails}"



<syncfusion:GridTextColumn HeaderText="Order ID" MappingName="OrderID" TextAlignment="Left" />

<syncfusion:GridTextColumn HeaderText="Customer ID" MappingName="CustomerID" />

<syncfusion:GridTextColumn HeaderText="Employee ID" MappingName="EmployeeID" TextAlignment="Right" />

<syncfusion:GridTextColumn HeaderText="Ship City" MappingName="ShipCity" />

<syncfusion:GridTextColumn HeaderText="Ship Country" MappingName="ShipCountry" />

<syncfusion:GridTextColumn DisplayBinding="{Binding Path=Freight, StringFormat='{}{0:c}'}" TextAlignment="Right" />

<syncfusion:GridTemplateColumn Width="50" MappingName="" AllowFiltering="False" AllowSorting="False">



<Button Width="30" Height="30" Command="{Binding ElementName=syncgrid, Path=DataContext.EditCommand}" CommandParameter="{Binding}">








Added TemplateColumn with button and changed NavigationMode to Cell.

  • In file OrderInfoViewModel.ch:

namespace DataBindingDemo


public class Command<T> : ICommand


public event EventHandler CanExecuteChanged;

public Action<T> Action;

public bool CanExecute(object parameter)


return true


public void Execute(object parameter)





public class OrderInfoViewModel : NotificationObject


public ICommand EditCommand




return new Command<Orders>()


Action = (order) => { /*DO things with order*/ }




public OrderInfoViewModel()


OrdersListDetails = new OrderInfoRepository().PopulateOrders(200);



Added command class and EditCommand to OrderInfoViewModel class.

Everything else is unchanged.Hope it's clear enouph. Whenever the button "Edit" is pressend the Exception is thrown. Can someone explain what I'm doing wrong? As I said changing the NavigationMode to Row make the code run without problems. Am I missing something?

Cheers Antoine

1 Reply

GT Gnanasownthari Thirugnanam Syncfusion Team July 31, 2017 06:04 PM UTC

Hi Antoine, 
We have analyzed your query based on your given code snippet. We have found that in your code you have missed the MappingName for GridTemplateColumn. We have prepared the sample based on your given code snippet, you can download the same from below mentioned location.  
If it is different from your requirement please revert by modified sample. It will be helpful for us to analyze further on this. 
Sample location: 
You can use GridUnBoundColumn with some unique name for MappingName if you don't want to map any data field.  
Refer the below UG link: 
Gnanasownthari T. 

Live Chat Icon For mobile
Up arrow icon