This worked on a different project and I have followed everything to the letter but no luck on my current project. Both task and risks objects are populated correctly when I inspect the values in code. But I get the browser error below when I run the code. If I leave out the GridForeignColumn from the code the grid displays correctly. Is there anything obvious I'm doing wrong? I'm using version 19.4.0.41
This is my code:
<SfTreeGrid @ref="treeGrid" ID="grid" DataSource="@tasks" IdMapping="Id" ParentIdMapping="ParentId" TreeColumnIndex="1" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Save", "Cancel" })" AllowExcelExport="true" AllowPdfExport="true" AllowReordering="true" AllowFiltering="true" AllowMultiSorting="true" AllowPaging="false" AllowResizing="true" AllowRowDragAndDrop="true" AllowSelection="true" AllowSorting="true" AllowTextWrap="true" AutoCheckHierarchy="true" EnableCollapseAll="true">
<TreeGridEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true" AllowEditOnDblClick="true" NewRowPosition="Syncfusion.Blazor.TreeGrid.RowPosition.Below" />
<Syncfusion.Blazor.TreeGrid.TreeGridEvents TValue="Models::Task" RowDataBound="OnRowDataBound" OnActionBegin="ActionBegin" OnActionComplete="ActionComplete" RowDropped="RowDropped" Expanded="Expanded" />
<Syncfusion.Blazor.TreeGrid.TreeGridSelectionSettings Type="Syncfusion.Blazor.Grids.SelectionType.Multiple" />
<TreeGridColumns>
<TreeGridColumn Field=@nameof(Models::Task.Id) HeaderText="Id" IsIdentity="true" IsPrimaryKey="true" Visible="false" />
<TreeGridColumn Field=@nameof(Models::Task.Name) HeaderText="Name" />
<TreeGridColumn Field=@nameof(Models::Task.StartDate) HeaderText="Start Date" />
<TreeGridColumn Field=@nameof(Models::Task.EndDate) HeaderText="End Date" />
<GridForeignColumn Field=@nameof(Models::Task.RiskId) ForeignKeyField="Id" ForeignKeyValue="Name" ForeignDataSource="@risks" HeaderText="Risk"></GridForeignColumn>
</TreeGridColumns>
</SfTreeGrid>
Models:
public partial class Risk
{
public Risk()
{
Tasks = new HashSet();
}
public int Id { get; set; }
public string Name { get; set; }
public string Code { get; set; }
public virtual ICollectionTasks { get; set; }
}
public partial class Task
{
public Task()
{
}
public int Id { get; set; }
public int? ParentId { get; set; }
public string Name { get; set; }
public DateTime? StartDate { get; set; }
public DateTime? EndDate { get; set; }
public int RiskId { get; set; }
public virtual EstimateVersion EstimateVersion { get; set; }
public virtual MeasurementUnit MeasurementUnit { get; set; }
public virtual Task Parent { get; set; }
public virtual Risk Risk { get; set; }
}
Error:
Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
at Syncfusion.Blazor.Grids.GridForeignColumn`1[[Blahblahblah.Models.Risk, SoftwareTools.Tarvio.Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].OnParametersSet()
at Microsoft.AspNetCore.Components.ComponentBase.CallOnParametersSetAsync()
at Microsoft.AspNetCore.Components.ComponentBase.SetParametersAsync(ParameterView parameters)
at Syncfusion.Blazor.SfDataBoundComponent.SetParametersAsync(ParameterView parameters)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.SupplyCombinedParameters(ParameterView directAndCascadingParameters)