Is there a way to support editing an object (key/value pair) where the value field is an object and can be of a different type for each record?
Current issue is error in editor saying:
Argument 1: cannot convert from object to string
public class KeyValue
{
public string Key { get; set; }
public object Value { get; set; }
}
<div>
<div>
<TelerikGrid Data="@KeyValues"
@ref="@Grid"
EditMode="GridEditMode.Incell"
OnStateInit="@((GridStateEventArgs<LabelEntry> args) => OnStateInitHandler(args))">
<GridColumns>
<GridColumn Field="Key"
Editable="false" />
<GridColumn Field="Value"
Editable="true">
<EditorTemplate>
@{
CurrentEntry = context as KeyValue;
if (CurrentEntry.Value.GetType().ToString().Equals("System.String", StringComparison.CurrentCultureIgnoreCase))
{
<TelerikTextBox @bind-Value="@CurrentEntry.Value" />
}
else if(CurrentEntry.Value.GetType().ToString().Equals("System.Int32", StringComparison.CurrentCultureIgnoreCase))
{
<TelerikNumericTextBox @bind-Value="@CurrentEntry.Value"/>
}
}
</EditorTemplate>
</GridColumn>
</GridColumns>
</TelerikGrid>
</div>
</div>
</div>
I got further with this. I realized that each editor has a specific type it needs to bind with. The TelerikTextBox uses a string and the TelerikNumericTextBox uses numeric type. I added the 2 types to my model and bound to them. I load the appropriate field when receiving the data in the parameter method and move data from the specific type to the normal object field during UpdateHandler.
The remaining issue is with the TelerikNumericTextBox that it is not picking up the new value. The editor shows the correct value, but when leaving the editor the grid does not show the new value. The model does have the correct value in both Value and ValueInt fields. The TelerikTextBox works.