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

GridtemplateColumn exception (WinRT)

I'm trying to get the simplest scenario possible working, based on my requirements, but keep getting exceptions from SfDataGrid.

Using a TemplateColumn with inline cell template. Simplified it to just show a Label, but even that won't work.

Versions: 
  • Syncfusion Essentials Xamarin 13.4.0.53
  • Xamarin.Forms 1.5.1.6471 (for WinRT compatibility)
  • Visual Studio 2015
XAML
        <xForms:SfDataGrid Grid.Row="1"
                           AutoGenerateColumns="False"
                           ColumnSizer="Star"
                           ItemsSource="{Binding View}"
                           SelectionMode="None"
                           ShowRowHeader="False">
            <xForms:SfDataGrid.Columns>
                <xForms:GridTemplateColumn>
                    <xForms:GridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Grid ColumnSpacing="3" Padding="0">
                                <!--<Grid.BindingContext>
                                    <viewModels:TimeLogTypeViewModel />
                                </Grid.BindingContext>-->

                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="25" />
                                    <ColumnDefinition Width="25" />
                                    <!--  WORK AROUND FOR LISTVIEW SCROLLBAR  -->
                                    <ColumnDefinition Width="10" />
                                </Grid.ColumnDefinitions>

                                <Label FontSize="{StaticResource TitleFontSize}"
                                       HorizontalOptions="StartAndExpand"
                                       Text="{Binding Model.Name}"
                                       TextColor="Black" />
                            </Grid>
                        </DataTemplate>
                    </xForms:GridTemplateColumn.CellTemplate>
                </xForms:GridTemplateColumn>
            </xForms:SfDataGrid.Columns>
        </xForms:SfDataGrid>

Exception Stack Trace:

System.ArgumentNullException: Value cannot be null.
Parameter name: key
   at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
   at Syncfusion.Data.ItemPropertiesProvider.GetValue(Object record, String property)
   at Syncfusion.SfDataGrid.XForms.GridCellTemplateRenderer.OnUpdateCellValue(DataColumnBase dataColumn)
   at Syncfusion.SfDataGrid.XForms.GridCellRendererBase.UpdateCellValue(DataColumnBase dataColumn)
   at Syncfusion.SfDataGrid.XForms.DataColumn.OnInitializeColumnElement(Object


8 Replies

SL Sathya Lakshmanan Syncfusion Team February 22, 2016 12:58 PM UTC

Hi Thomas,

Thanks for using Syncfusion Products.

We have analyzed your query and we were able to reproduce the issue from our side. This is a sample side issue. You must set a MappingName for all the columns you create in SfDataGrid. The columns in SfDataGrid are created based on the mapping name of the columns which must be a property available in the bound data source. Only then the grid will be able to create a column. We have modified your code and highlighted the changes we have done in your code to make it work for your reference. 

For more information about template column please refer the below user documentation link.
http://help.syncfusion.com/xamarin/sfdatagrid/column-types-forms#gridtemplatecolumn  

Refer the below code example which includes setting a mapping name for the template column to fix the reported issue.


<xForms:SfDataGrid Grid.Row="1"

                    AutoGenerateColumns="False"

                    ColumnSizer="Star"

                    ItemsSource="{Binding View}"

                    SelectionMode="None"

                    ShowRowHeader="False">

  <xForms:SfDataGrid.Columns>

    <xForms:GridTemplateColumn MappingName="">

      <xForms:GridTemplateColumn.CellTemplate>

        <DataTemplate>

          <Grid ColumnSpacing="3" Padding="0">

            <!--<Grid.BindingContext>

                                <viewModels:TimeLogTypeViewModel />

                            </Grid.BindingContext>-->


            <Grid.ColumnDefinitions>

              <ColumnDefinition Width="*" />

              <ColumnDefinition Width="25" />

              <ColumnDefinition Width="25" />

                <!--WORK AROUND FOR LISTVIEW SCROLLBAR--> 

              <ColumnDefinition Width="10" />

            </Grid.ColumnDefinitions>

              <Label FontSize="{StaticResource TitleFontSize}"

                    HorizontalOptions="StartAndExpand"

                    Text="{Binding Model.Name}"

                    TextColor="Black" />

          </Grid>

        </DataTemplate>

      </xForms:GridTemplateColumn.CellTemplate>

    </xForms:GridTemplateColumn>

  </xForms:SfDataGrid.Columns>

</xForms:SfDataGrid>


Regards,
Sathya



TH ThomasHagström March 12, 2016 07:07 PM UTC

Thanks, this solved the issue


HN Harikrishnan N Syncfusion Team March 14, 2016 05:25 AM UTC

Hi Thomas,

Thanks for the update.

Please let us know if you require further assistance on this.

Regards,
Harikrishnan



TH ThomasHagström April 30, 2016 09:57 AM UTC

I seem to be back at this issue, at least on Android - works on Win 8.1.

On Android I get

Set Method not found for 'Element'

I have a datagrid defiend as such.

            <xForms:SfDataGrid x:Name="ListView"
                               Grid.Row="3"
                               AutoGenerateColumns="False"
                               BackgroundColor="Transparent"
                               ColumnSizer="Star"
                               HeaderRowHeight="0"
                               HorizontalOptions="{Binding HorizontalOptions}"
                               ItemsSource="{Binding ItemsSource,
                                                     Mode=OneWay}"
                               SelectionMode="{Binding SelectionMode,
                                                       Mode=OneWay}"
                               ShowRowHeader="False"
                               WidthRequest="{Binding WidthRequest,
                                                      Mode=OneWay}" />

And then add a DataTemplateColumn:

            this.ListView.Columns.Add(gridTemplateColumn);            var gridTemplateColumn = new GridTemplateColumn { CellTemplate = this.ItemTemplate, MappingName = "", HeaderText = "" };

The content of ItemTemplate is  simple Label

                </DataTemplate>                           TextColor="Black" />                           Text="{Binding Model.Description}"                    <Label FontSize="15"                <DataTemplate>


TH ThomasHagström May 1, 2016 09:52 AM UTC

 
Set Method not found for 'Element'
 at System.Reflection.MonoProperty.SetValue (System.Object obj, System.Object value, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] index, System.Globalization.CultureInfo culture) [0x00014] in /Users/builder/data/lanes/2923/af4f4972/source/mono/mcs/class/corlib/System.Reflection/MonoProperty.cs:433
  at System.Reflection.PropertyInfo.SetValue (System.Object obj, System.Object value) [0x00000] in /Users/builder/data/lanes/2923/af4f4972/source/mono/mcs/class/corlib/System.Reflection/PropertyInfo.cs:118
  at Syncfusion.SfDataGrid.XForms.Droid.ExtendedScrollViewRenderer.OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs`1 e) [0x0002a] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetElement (Xamarin.Forms.Platform.Android.TElement element) [0x000fc] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00027] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x0001f] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementPackager.AddChild (Xamarin.Forms.VisualElement view, IVisualElementRenderer oldRenderer, Xamarin.Forms.Platform.Android.RendererPool pool, Boolean sameChildren) [0x00023] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementPackager.SetElement (Xamarin.Forms.VisualElement oldElement, Xamarin.Forms.VisualElement newElement) [0x0010d] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementPackager.Load () [0x0000d] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetPackager (Xamarin.Forms.Platform.Android.VisualElementPackager packager) [0x00007] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetElement (Xamarin.Forms.Platform.Android.TElement element) [0x00118] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00027] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x0001f] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementPackager.AddChild (Xamarin.Forms.VisualElement view, IVisualElementRenderer oldRenderer, Xamarin.Forms.Platform.Android.RendererPool pool, Boolean sameChildren) [0x00023] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementPackager.SetElement (Xamarin.Forms.VisualElement oldElement, Xamarin.Forms.VisualElement newElement) [0x0010d] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementPackager.Load () [0x0000d] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetPackager (Xamarin.Forms.Platform.Android.VisualElementPackager packager) [0x00007] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetElement (Xamarin.Forms.Platform.Android.TElement element) [0x00118] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00027] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x0001f] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementPackager.AddChild (Xamarin.Forms.VisualElement view, IVisualElementRenderer oldRenderer, Xamarin.Forms.Platform.Android.RendererPool pool, Boolean sameChildren) [0x00023] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementPackager.SetElement (Xamarin.Forms.VisualElement oldElement, Xamarin.Forms.VisualElement newElement) [0x0010d] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementPackager.Load () [0x0000d] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetPackager (Xamarin.Forms.Platform.Android.VisualElementPackager packager) [0x00007] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetElement (Xamarin.Forms.Platform.Android.TElement element) [0x00118] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00027] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x0001f] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementPackager.AddChild (Xamarin.Forms.VisualElement view, IVisualElementRenderer oldRenderer, Xamarin.Forms.Platform.Android.RendererPool pool, Boolean sameChildren) [0x00023] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementPackager.SetElement (Xamarin.Forms.VisualElement oldElement, Xamarin.Forms.VisualElement newElement) [0x0010d] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementPackager.Load () [0x0000d] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetPackager (Xamarin.Forms.Platform.Android.VisualElementPackager packager) [0x00007] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetElement (Xamarin.Forms.Platform.Android.TElement element) [0x00118] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00027] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x0001f] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementPackager.AddChild (Xamarin.Forms.VisualElement view, IVisualElementRenderer oldRenderer, Xamarin.Forms.Platform.Android.RendererPool pool, Boolean sameChildren) [0x00023] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementPackager.SetElement (Xamarin.Forms.VisualElement oldElement, Xamarin.Forms.VisualElement newElement) [0x0010d] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementPackager.Load () [0x0000d] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetPackager (Xamarin.Forms.Platform.Android.VisualElementPackager packager) [0x00007] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetElement (Xamarin.Forms.Platform.Android.TElement element) [0x00118] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00027] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x0001f] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementPackager.AddChild (Xamarin.Forms.VisualElement view, IVisualElementRenderer oldRenderer, Xamarin.Forms.Platform.Android.RendererPool pool, Boolean sameChildren) [0x00023] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementPackager.SetElement (Xamarin.Forms.VisualElement oldElement, Xamarin.Forms.VisualElement newElement) [0x0010d] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementPackager.Load () [0x0000d] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetPackager (Xamarin.Forms.Platform.Android.VisualElementPackager packager) [0x00007] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetElement (Xamarin.Forms.Platform.Android.TElement element) [0x00118] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00027] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x0001f] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.Platform.AddChild (Xamarin.Forms.VisualElement view, Boolean layout) [0x00015] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.Platform.SetPage (Xamarin.Forms.Page newRoot) [0x00090] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.FormsApplicationActivity.InternalSetPage (Xamarin.Forms.Page page) [0x000b7] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.FormsApplicationActivity.SetMainPage () [0x0000c] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.FormsApplicationActivity.LoadApplication (Xamarin.Forms.Application application) [0x0002d] in <filename unknown>:0
  at HLI.TimeNodes.Droid.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x00014] in C:\Source\TimeNodes\HLI.TimeNodes.Droid\HLI.TimeNodes.Droid\MainActivity.cs:44
  at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (IntPtr jnienv, IntPtr native__this, IntPtr native_savedInstanceState) [0x00011] in /Users/builder/data/lanes/2923/b4be22e9/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.App.Activity.cs:2426
  at (wrapper dynamic-method) System.Object:395eae9a-dfb6-4fb9-92bf-5f3e1988e859 (intptr,intptr,intptr)


HN Harikrishnan N Syncfusion Team May 2, 2016 09:02 PM UTC

Hi Thomas,

We were unable to reproduce the issue from our side. We have created a sample for your reference and you can download the same from below link.

Sample link: http://www.syncfusion.com/downloads/support/forum/122148/ze/DemoSample-279399199

Please check whether the Xamarin NuGets are in line with the version supported by SfDataGrid. In case, if the issue still persists at your end, please revert us by modifying the sample to reproduce the issue along with clear replication procedure.

Note: Please restore the Xamarin NuGets and refer the Syncfusion assemblies manually for the above sample to compile and run.

Regards,
Harikrishnan 




TH ThomasHagström May 6, 2016 10:59 AM UTC

Yeah, I built on another machine and got it working now. Thanks.


HN Harikrishnan N Syncfusion Team May 9, 2016 04:49 AM UTC

Hi Thomas,

Thanks for the update.

Please let us know if you require further assistance on this.

Regards,
Harikrishnan
 



Loader.
Up arrow icon