Problems getting sfcombobox working with Sfgrid

I have a grid with one column.  I'm trying to add rows to it based on a lookup list.
The grid displays the data correctly.  When I enter edit mode the combo box displays the Tags: "Weights", "Cardio", "Toning", "HIT", "Dumbell".  But when I select an item I get a null reference.

How can I fix this issue?

My SFGrid data source uses:

public List<ExerciseTagsModel> GridData = new List<ExerciseTagsModel>();

public class ExerciseTagsModel
{
    public int ID { get; set; }

    public int ExerciseID { get; set; }

    public string Tag { get; set; }
}

The SFCombobox data source uses:

Tags = new List<string>() { "Weights", "Cardio", "Toning", "HIT", "Dumbell" };

Here's the grid markup:

<SfGrid TValue="ExerciseTagsModel"
        @ref="@gridInstance"
        DataSource="@GridData"
        Toolbar="@(new List<string>() {
        "Add", "Delete", "Cancel"
    })">

    <GridEditSettings Mode="EditMode.Normal"
                      AllowAdding="true"
                      AllowDeleting="true"
                      AllowEditing="true"
                      ShowDeleteConfirmDialog="true">
    </GridEditSettings>

    <GridEvents DataBound="DataBoundHandler"
                OnActionComplete="ActionCompletedHandler"
                TValue="ExerciseTagsModel">
    </GridEvents>

    <GridColumns>
        <GridColumn Visible="false"
                    Field=@nameof(ExerciseTagsModel.ID)
                    HeaderText="ID"
                    TextAlign="TextAlign.Center"
                    IsPrimaryKey="true">
        </GridColumn>
          <GridColumn Field=@nameof(ExerciseTagsModel.Tag)
                 HeaderText="@L["Tags_"]"
                 TextAlign="TextAlign.Center">
                <EditTemplate>
                  <SfComboBox @bind-Value="@tagValue"
                         AllowCustom="true"
                         TItem="string"
                         TValue="string"
                         DataSource="@Tags"
                         AllowFiltering="true">
                  </SfComboBox>        
             </EditTemplate>
          </GridColumn>
    </GridColumns>
</SfGrid>

Here is the NullReferenceExceptions text:

System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=Syncfusion.Blazor
  StackTrace:
   at Syncfusion.Blazor.Grids.Internal.PropertyInfoHelper.CreateAccessor(PropertyInfo propertyInfo)


3 Replies 1 reply marked as answer

VN Vignesh Natarajan Syncfusion Team February 22, 2021 07:34 AM UTC

Hi Matthew,  

Thanks for contacting Syncfusion support.  

Query: “ When I enter edit mode the combo box displays the Tags: "Weights", "Cardio", "Toning", "HIT", "Dumbell".  But when I select an item I get a null reference. 

We have analyzed the reported issue by preparing a sample using your code example and we are not able to reproduce the reported issue at our end. Kindly refer the sample from below which we have prepared  


After referring the sample, if you are still facing the reported issue .Kindly share the following details.  

  1. Share more details about the issue you are facing.
  2. Share the video demonstration of the issue along with replication procedure.
  3. Share the details about the Grid datasource.
  4. If possible share the issue reproducible sample or try to reproduce the reported issue in provided sample.

Above requested details will be very helpful for us to validate the reported issue at our end and provide solution as early as possible. 

Regards, 
Vignesh Natarajan  



MA Matthew February 22, 2021 12:29 PM UTC

Thanks for replying back so quickly.  I got my code to work by using your example.

I had to change my code from:

<SfComboBox @bind-Value="@tagValue"

To:

<SfComboBox @bind-Value="@((context as ExerciseTagsModel).Tag)"

Marked as answer

VN Vignesh Natarajan Syncfusion Team February 23, 2021 04:39 AM UTC

Hi Matthew,  

Thanks for the update.  

We are glad to hear that you have resolved your query using our sample.  

Please get back to us if you have further queries.  

Regards, 
Vignesh Natarajan 




Loader.
Up arrow icon