Cannot implicitly convert type With Bound Grid

I have a Blazor solution with 3 project.  There is the main app, a rest service for data, and a shared class project for EF. 


Lots of detail below.  What is interesting is that I have done this for another EF class.  Exact same code (as far as I can tell),  and it works perfectly.   I feel I have flubbed something in the code.  The error message isn't really helping me out.   Hopefully someone has seen something like this.


I am getting the following error.

CS0029

Cannot implicitly convert type 'Syncfusion.Blazor.Grids.SfGrid<dataCatAdminBLZ.Shared.FieldGrouping>' to 'Syncfusion.Blazor.Grids.SfGrid<dataCatAdminBLZ.App.Pages.FieldGroupingEdit>'

dataCatAdminBLZ.App

..<path>\Files\GIT\dataCatAdminBLZ\dataCatAdminBLZ.App\Pages\FieldGroupingEdit.razor 1 Active


The first part .Shared.FieldGrouping  is referencing an class with properties defining a database table

The second part is referring to the blazor page.    In the CS partial class for the page there is code that does:

  protected override async Task OnInitializedAsync()

        {

            FieldGroupingA = (await FieldGroupingDataServiceP.FieldGroupings()).ToList();

        }




I have build a razor page with a sfgrid component on it.  The grid binds to the class define in the CS.


<SfGrid DataSource=@FieldGroupingA class="mr-2" @ref="@Grid_Resolved"

        AllowPaging="true"

        AllowFiltering="false"

        AllowSorting="true"

        AllowTextWrap="true"

        AllowResizing="true"

        AllowGrouping="false"

        RowHeight="30"

        Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })">


    <GridEditSettings AllowAdding="true"

                      AllowDeleting="true"

                      AllowEditing="true" />


    <GridPageSettings PageSize="40"></GridPageSettings>


    @*<GridEvents OnRecordDoubleClick="RecordDoubleClickHandler" TValue="FileTemplateHeader"></GridEvents>*@



    <GridColumns>

        <GridColumn Field=@nameof(FieldGrouping.Agsan) HeaderText="AGSAN" IsPrimaryKey="true" TextAlign="TextAlign.Center" Width="4" />

        <GridColumn Field=@nameof(FieldGrouping.GrpName) HeaderText="Group Name" IsPrimaryKey="false" TextAlign="TextAlign.Left" Width="20"></GridColumn>

        <GridColumn Field=@nameof(FieldGrouping.GrpDesc) HeaderText="Group Desc" IsPrimaryKey="false" TextAlign="TextAlign.Left" Width="30"></GridColumn>

    </GridColumns>

</SfGrid>





7 Replies 1 reply marked as answer

JP Jeevakanth Palaniappan Syncfusion Team September 22, 2021 07:36 AM UTC

Hi Marc, 
 
Greetings from Syncfusion support. 
 
We have checked your query and based on the error we found that you are facing some type issues. Kindly check whether you have defined the proper TValue for the Datasource property and a proper return type for the FieldGroupings method which you have invoked from the below code. 
 
 protected override async Task OnInitializedAsync() 
 { 
            FieldGroupingA = (await FieldGroupingDataServiceP.FieldGroupings()).ToList(); 
} 
 
 
Get back to us if you have any other queries. 
 
Attached the getting started documentation below for your reference. 
 
Regards, 
Jeevakanth SP. 



MA Marc September 22, 2021 11:49 AM UTC

Attached are 2 screen shots showing the type.  I have done this with another EF table and it works fine.  This code looks the same, but clearly something is different.  Attached is also a small sample solution demonstrating the issue and a screen shot showing the visual studio form and error message.


Thanks.


Attachment: dataCatAdminBLZ_5afe2dbb.7z


JP Jeevakanth Palaniappan Syncfusion Team September 23, 2021 06:35 AM UTC

Hi Marc, 

We have checked your code and we would like to inform you that the TValue(SfGrid<TValue>) should be same as the class you have defined in the grid definition. Please change the below highlighted code in FieldGroupingEdit.cs file to resolve your issue. 


FieldGroupingEdit.cs 
SfGrid<FieldGrouping> Grid_Resolved; 

The above TValue(FieldGrouping) should be same with the below codes. 
<SfGrid DataSource=@FieldGroupingA class="mr-2" @ref="@Grid_Resolved" 
        AllowPaging="true" 
        AllowFiltering="false" 
        AllowSorting="true" 
        AllowTextWrap="true" 
        AllowResizing="true" 
        AllowGrouping="false" 
        RowHeight="30" 
        Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })"> 
    <GridEditSettings AllowAdding="true" 
                      AllowDeleting="true" 
                      AllowEditing="true" /> 
    <GridPageSettings PageSize="40"></GridPageSettings> 
    <GridColumns> 
        <GridColumn Field=@nameof(FieldGrouping.Agsan) HeaderText="AGSAN" IsPrimaryKey="true" TextAlign="TextAlign.Center" Width="4" /> 
        <GridColumn Field=@nameof(FieldGrouping.GrpName) HeaderText="Group Name" IsPrimaryKey="false" TextAlign="TextAlign.Left" Width="20"></GridColumn> 
        <GridColumn Field=@nameof(FieldGrouping.GrpDesc) HeaderText="Group Desc" IsPrimaryKey="false" TextAlign="TextAlign.Left" Width="30"></GridColumn> 
    </GridColumns> 
</SfGrid> 

Documentation and demo to getting started with grid component 

Get back to us if you have any other queries. 

Regards, 
Jeevakanth SP. 


Marked as answer

MA Marc September 23, 2021 05:23 PM UTC

Thanks.  Cannot believe I missed that, but I knew it was going to be something small.


In the CS file, would you explain to me the meaning of this line?

SfGrid<FieldGrouping> Grid_Resolved; 


In the razor file, seems to already have the reference to the dataset.  Not sure I understand the purpose of this line.


Thanks again for the help.



JP Jeevakanth Palaniappan Syncfusion Team September 24, 2021 07:37 AM UTC

Hi Marc, 
 
Please find the details of your query below. 
 
Query: In the CS file, would you explain to me the meaning of this line? 
SfGrid<FieldGrouping> Grid_Resolved;  
Grid_Resolved is the reference to the SfGrid component you have rendered in the razor file. The grid component is strongly typed component and you have to use the same model class in both the column definition and in the reference also. Grid reference type is SfGrid<TValue> and here TValue is the model class(FieldGrouping). 
 
Query: In the razor file, seems to already have the reference to the dataset.  
 
Based on the code in razor file, you have set @ref to Grid_Resolved which is the variable you have defined in the CS file. If you remove the Grid_Resolved variable in CS file then you will get the error in the razor file. So we are quite unclear about this line. 
 
Regards, 
Jeevakanth SP. 



MA Marc September 24, 2021 09:55 AM UTC

Thanks for all of you help.  I appreciate you responses.

Marc.



JP Jeevakanth Palaniappan Syncfusion Team September 27, 2021 05:24 AM UTC

Hi Marc, 

You are most welcome. Please get back to us if you have any other queries. 

Regards, 
Jeevakanth SP. 


Loader.
Up arrow icon