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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

GridTemplateColumn with button throw System.NullReferenceException

Thread ID:





131819 Jul 28,2017 10:06 AM UTC Jul 31,2017 06:04 PM UTC WPF 1
Tags: SfDataGrid
Nyx Wallace
Asked On July 28, 2017 10:06 AM UTC

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

Gnanasownthari Thirugnanam [Syncfusion]
Replied On 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. 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon 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.Close Icon