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.

GridTemplateColumn with button throw System.NullReferenceException

Thread ID:

Created:

Updated:

Platform:

Replies:

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

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 15.2.0.46.
     
Changes:
  •      In file ListViewPage.xaml:

<sync:SfDataGrid x:Name="syncgrid"

AllowFiltering="True"

AutoGenerateColumns="False"

ColumnSizer="Star"

ItemsSource="{Binding OrdersListDetails}"

NavigationMode="Cell">

<sync:SfDataGrid.Columns>

<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">

<syncfusion:GridTemplateColumn.CellTemplate>

<DataTemplate>

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

Edit

</Button>

</DataTemplate>

</syncfusion:GridTemplateColumn.CellTemplate>

</syncfusion:GridTemplateColumn>

</sync:SfDataGrid.Columns>

</sync:SfDataGrid>

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)

{

Action.Invoke((T)parameter);

}

}


public class OrderInfoViewModel : NotificationObject

{

public ICommand EditCommand

{

get

{

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 02:04 PM

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: 
 
Regards, 
Gnanasownthari T. 
 


CONFIRMATION

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.

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.

;