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.
Syncfusion Feedback

Columns set binding

Thread ID:

Created:

Updated:

Platform:

Replies:

121394 Dec 9,2015 02:15 PM UTC Oct 3,2018 11:04 AM UTC Xamarin.Forms 8
loading
Tags: SfDataGrid
Giorgos Papadakis
Asked On December 9, 2015 02:15 PM UTC

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 01:43 PM UTC

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




//App.cs

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


dataGrid.Columns.Add(orderIdColumn);

dataGrid.Columns.Add(customerIdColumn);

dataGrid.Columns.Add(customerColumn);
dataGrid.Columns.Add(countryColumn);       



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.

Regards,
Prasanth

Giorgos Papadakis
Replied On December 14, 2015 01:15 PM UTC

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; }
            set
            {
                _SalesGridColumns = value;
                OnPropertyChanged("SalesGridColumns");
            }
        }

Prasanth Karthikeyan [Syncfusion]
Replied On December 15, 2015 01:41 PM UTC

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.

Regards,
Prasanth

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

Hi Giorgos Papadakis,

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

http://www.syncfusion.com/forums/121657/essential-studio-2015-volume-4-final-release-v13-4-0-53-is-available-for-download


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.

Regards,
Dharmendar D


Chris Hu
Replied On October 6, 2017 09:52 PM UTC

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.

Thanks


Vimal Prabhu Manohkaran [Syncfusion]
Replied On October 9, 2017 12:52 PM UTC

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.

Regards,
Vimal Prabhu
 


IT Operations
Replied On October 2, 2018 11:16 AM UTC

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.

Regards,
Vimal Prabhu
 


Hi Vimal,

Any update on this issue? I am on SFDatagrid version 16.2.0.50. And I am still getting "SfDataGrid.Columns can't be null" when binding the columns to a column source in the view model.

Vigneshkumar Ramasamy [Syncfusion]
Replied On October 3, 2018 11:04 AM UTC

Hi Giorgos, 
 
Thanks for your update. 
 
We can reproduce the issue "Exception occurs if the property is binded to the SfDataGrid.Columns" in XAML code. The issue will be fixed and included in 2018 Volume 3 SP - 1 release which will be rolled out by the end of October 2018. We appreciate your patience until then. 
As of now, for fixing the issue in sample level, you can bind the property to the SfDataGrid.Columns in code behind. 
 
Regards,
Vigneshkumar R 


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.

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

;