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.

Columns set binding

Thread ID:





121394 Dec 9,2015 09:15 AM Oct 9,2017 08:52 AM Xamarin.Forms 6
Tags: SfDataGrid
Giorgos Papadakis
Asked On December 9, 2015 09:15 AM

I have create a view to display an sfdatagrid and  set binding to Columns through grid.SetBinding(SfDataGrid.ColumnsProperty, "SalesGridColumns").
SalesGridColumns returns Columns from the viewmodel

var grid = new SfDataGrid
                AllowSorting = true,
                AutoGenerateColumns = false,
                ColumnSizer = ColumnSizer.Star,
                SelectionMode = SelectionMode.Single,

grid.SetBinding(SfDataGrid.ColumnsProperty, "SalesGridColumns");
grid.SetBinding(SfDataGrid.ItemsSourceProperty, "SalesGridData");

But i get the following error

12-09 16:02:53.308 E/mono    (26308):
12-09 16:02:53.308 E/mono    (26308): Unhandled Exception:
12-09 16:02:53.308 E/mono    (26308): System.Exception: SfDataGrid.Columns can't be null
12-09 16:02:53.308 E/mono    (26308):   at Syncfusion.SfDataGrid.XForms.SfDataGrid.OnColumnsPropertyChanged (Xamarin.Forms.BindableObject bindable, Syncfusion.SfDataGrid.XForms.Columns oldValue, Syncfusion.SfDataGrid.XForms.Columns newValue) [0x0001f] in <filename unknown>:0
12-09 16:02:53.308 E/mono    (26308):   at Xamarin.Forms.BindableProperty+<>c__DisplayClass13_0`2[TDeclarer,TPropertyType].<Create>b__1 (Xamarin.Forms.BindableObject bindable, System.Object oldValue, System.Object newValue) [0x00000] in <filename unknown>:0
12-09 16:02:53.308 E/mono    (26308):   at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindablePropertyContext context, System.Object value, Boolean currentlyApplying, SetValueFlags attributes, Boolean silent) [0x0010e] in <filename unknown>:0
12-09 16:02:53.308 E/mono    (26308):   at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes) [0x0014b] in <filename unknown>:0
12-09 16:02:53.308 E/mono    (26308):   at Xamarin.Forms.BindingExpression.ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, Boolean fromTarget) [0x0020b] in <filename unknown>:0
12-09 16:02:53.308 E/mono    (26308):   at Xamarin.Forms.BindingExpression.Apply (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property) [0x0006b] in <filename unknown>:0
12-09 16:02:53.308 E/mono    (26308):   at Xamarin.Forms.Binding.Apply (System.Object newContext, Xamarin.Forms.BindableObject bindObj, Xamarin.Forms.BindableProperty targetProperty) [0x00042] in <filename unknown>:0
12-09 16:02:53.308 E/mono    (26308):   at Xamarin.Forms.BindableObject.SetBinding (Xamarin.Forms.BindableProperty targetProperty, Xamarin.Forms.BindingBase binding, Boolean fromStyle) [0x000af] in <filename unknown>:0
12-09 16:02:53.308 E/mono    (26308):   at Xamarin.Forms.BindableObject.SetBinding (Xamarin.Forms.BindableProperty targetProperty, Xamarin.Forms.BindingBase binding) [0x00000] in <filename unknown>:0
12-09 16:02:53.308 E/mono    (26308):   at Xamarin.Forms.BindableObjectExtensions.SetBinding (Xamarin.Forms.BindableObject self, Xamarin.Forms.BindableProperty targetProperty, System.String path, BindingMode mode, IValueConverter converter, System.String stringFormat) [0x0002a] in <filename unknown>:0
12-09 16:02:53.308 E/mono    (26308):   at ThesismBI.Views.Sales.SalesGridView..ctor () [0x00123] in M:\WORK\_vs.net\ThesisMobileProject\ThesisMobileMiddleWare\ThesismBI\ThesismBI\Views\Sales\SalesGridView.cs:96
12-09 16:02:53.308 E/mono    (26308):   at ThesismBI.Pages.Sales.SalesGridPage.RemoveDynamicResource (Xamarin.Forms.BindableProperty property) [0x00008] in M:\WORK\_vs.net\ThesisMobileProject\ThesisMobileMiddleWare\ThesismBI\ThesismBI\Pages\Sales\SalesGridPage.cs:20
12-09 16:02:53.308 E/mono    (26308):   at ThesismBI.Pages.Sales.SalesDashboardPage.SetDynamicResource (Xamarin.Forms.BindableProperty property, System.String key, Boolean fromStyle) [0x00058] in M:\WORK\_vs.net\ThesisMobileProject\ThesisMobileMiddleWare\ThesismBI\ThesismBI\Pages\Sales\SalesDashboardPage.cs:25
12-09 16:02:53.308 E/mono    (26308):   at ThesismBI.Pages.Sales.SalesSearchpage+<<OnAppearing>b__1_1>d.MoveNext () [0x0000f] in M:\WORK\_vs.net\ThesisMobileProject\ThesisMobileMiddleWare\ThesismBI\ThesismBI\Pages\Sales\SalesSearchpage.cs:83
12-09 16:02:53.308 E/mono    (26308): --- End of stack trace from previous location where exception was thrown ---

Prasanth Karthikeyan [Syncfusion]
Replied On December 10, 2015 08:43 AM

Hi Giorgos Papadakis,

We have analyzed your query “Exception thrown when setting binding for SfDataGrid.Columns collection”. The SfDataGrid.Columns property is a collection of GridColumns in which you can just directly add the columns created in the sample.

Please refer the below example code for manually adding the columns using columns collection


SfDataGrid dataGrid;

dataGrid = new SfDataGrid();

dataGrid.AutoGenerateColumns = false;

dataGrid.AutoGenerateColumns = false;

GridTextColumn orderIdColumn = new GridTextColumn();

orderIdColumn.MappingName = "OrderID";

orderIdColumn.HeaderText = "Order ID";

GridTextColumn customerIdColumn = new GridTextColumn();

customerIdColumn.MappingName = "CustomerID";

customerIdColumn.HeaderText = "Customer ID";

GridTextColumn customerColumn = new GridTextColumn();

customerColumn.MappingName = "Customer";

GridTextColumn countryColumn = new GridTextColumn();

countryColumn.MappingName = "ShipCountry";

countryColumn.HeaderText = "Ship Country";




For more details about adding the columns manually to SfDataGrid, please refer our UG documentation here.

Please let us know if you have any query.


Giorgos Papadakis
Replied On December 14, 2015 08:15 AM

I already new that how to manually add columns, but in order to keep my mvvm seperation add like to populate the collumn collection on the viewmodel and bind to the grid like . Why doesn't work in my approach?

on view
grid.SetBinding(SfDataGrid.ColumnsProperty, "SalesGridColumns");

on my viewmodel

Columns _SalesGridColumns;
        public Columns SalesGridColumns
            get { return _SalesGridColumns; }
                _SalesGridColumns = value;

Prasanth Karthikeyan [Syncfusion]
Replied On December 15, 2015 08:41 AM

Hi Giorgos Papadakis,

We have analyzed your query. We are able to reproduce the issue “Grid will not display while binding columns collections to ColumnsProperty using Setbinding” and we will fix the issue internally. The fix for this issue will be available in the upcoming Volume 4 main release which is scheduled to be rolled out by January, 2016.

Please let us know if you have any query.


Dharmendar Dhanasekar [Syncfusion]
Replied On January 18, 2016 12:21 AM

Hi Giorgos Papadakis,

We are glad to announce that our Essential Studio Volume 4, 2015 (Version is rolled out and is available for download under the following link.


We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance.

Dharmendar D

Chris Hu
Replied On October 6, 2017 05:52 PM

Hi SyncFusion Team,

This bug still occur as of today Oct 6, 2017. 

Try binding it in XAML or in code behind class constructor will give "System.Exception: SfDataGrid.Columns can't be null" exception.

The only work around is : bind the ColumnProperty dynamically in the ContentPage's OnBindingContextChanged EventHandler.

Please fix this bug.


Vimal Prabhu Manohkaran [Syncfusion]
Replied On October 9, 2017 08:52 AM

HI Chris,

We are able to reproduce the reported issue. The fix for this issue will be available in our upcoming 2017 Volume 4 Main Release which is expected to be rolled out on the last week of October. We appreciate your patience until then. We will let you know once the release rolls out.

Vimal Prabhu


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.