When deleting an record from an SfGrid's data source, an exception is thrown when the grid gets re-rendered. I am basically calling a method removing the currently selected item from the grids data source when a button in that item's grid row gets clicked.
Error Message:
crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Event 1525 is already tracked
Error: Event 1525 is already tracked
at e.update (https://localhost:44361/StreckerShop/_framework/blazor.webassembly.js:1:42982)
at e.setListener (https://localhost:44361/StreckerShop/_framework/blazor.webassembly.js:1:40575)
at e.applyAttribute (https://localhost:44361/StreckerShop/_framework/blazor.webassembly.js:1:36864)
at e.applyEdits (https://localhost:44361/StreckerShop/_framework/blazor.webassembly.js:1:33290)
at e.updateComponent (https://localhost:44361/StreckerShop/_framework/blazor.webassembly.js:1:32271)
at Object.t.renderBatch (https://localhost:44361/StreckerShop/_framework/blazor.webassembly.js:1:12134)
at Object.window.Blazor._internal.renderBatch (https://localhost:44361/StreckerShop/_framework/blazor.webassembly.js:1:61913)
at Object.w [as invokeJSFromDotNet] (https://localhost:44361/StreckerShop/_framework/blazor.webassembly.js:1:64435)
at _mono_wasm_invoke_js_blazor (https://localhost:44361/StreckerShop/_framework/dotnet.5.0.13.js:1:190800)
at wasm_invoke_iiiiii (wasm://wasm/00aba242:wasm-function[5611]:0xdda7f)
HTML
<SfGrid @ref="palettenGrid" TValue="VersandPalettenInfo" DataSource="@palettenListe" EnableVirtualization="true" EnableVirtualMaskRow="true" AllowSorting="false" AllowFiltering="false" Height="180" RowHeight="20">
<GridPageSettings PageSize="100"></GridPageSettings>
<GridColumns>
<GridColumn Width="50" TextAlign="TextAlign.Center">
<Template>
<i class="fas fa-trash-alt" style="color: #0;" @onclick='() => OnDelPalette((context as VersandPalettenInfo).Key)' />
</Template>
</GridColumn>
<GridIntegerColumn HeaderText="Anzahl" Field=@nameof(VersandPalettenInfo.Anzahl) Width="120" HeaderToolTip="Anzahl Paletten" HeaderTextAlign="TextAlign.Center" TextAlign="TextAlign.Center"> </GridIntegerColumn>
<GridIntegerColumn HeaderText="Gewicht (kg)" Field=@nameof(VersandPalettenInfo.Gewicht) Width="120" HeaderToolTip="Gesamtgewicht [kg]" HeaderTextAlign="TextAlign.Center" TextAlign="TextAlign.Center"></GridIntegerColumn>
</GridColumns>
</SfGrid>
Data Types
[Table("TAB_SPEDITIONSVERSAND")]
public partial class TAB_SPEDITIONSVERSAND
{
[Key]
[StringLength(3)]
public string PALETTENTYP { get; set; } = "";
public int LAENGE_CM { get; set; }
public int BREITE_CM { get; set; }
public int HOEHE_CM { get; set; }
[StringLength(2000)]
public string TEXT { get; set; } = "";
}
public class VersandPalettenInfo
{
public VersandPalettenInfo()
{
Info = new();
}
public VersandPalettenInfo(TAB_SPEDITIONSVERSAND i)
{
Info = i;
}
public TAB_SPEDITIONSVERSAND Info { get; set; }
public int Anzahl { get; set; } = 1;
public float Volumen => (float)(Laenge * Breite * Hoehe) / 1e6f;
public string Typ => Info.PALETTENTYP;
public int Laenge => Info.LAENGE_CM;
public int Breite => Info.BREITE_CM;
public int Hoehe => Info.HOEHE_CM;
public string Text => Info.TEXT;
}
Code
SfGridpalettenGrid;
public ListpalettenTypen = null;
public TAB_SPEDITIONSVERSAND palettenTyp = new();
protected ObservableCollectionpalettenListe = new ObservableCollection ();
void OnDelPalette(int key)
{
int i = 0;
foreach (VersandPalettenInfo pi in palettenListe)
{
if (pi.Key == key)
{
palettenKeys.ReleaseKey(pi.Key);
palettenListe.RemoveAt(i);
break;
}
i++;
}
StateHasChanged();
}
public void Setup ()
{
if (palettenTypen is null)
{
palettenTypen = new();
foreach (TAB_SPEDITIONSVERSAND p in SpeditionsversandCache.ValuesList)
palettenTypen.Add(p);
}
if (palettenListe.Count > 0)
palettenListe.Clear();
palettenListe.Add(new VersandPalettenInfo(palettenTypen [0]));
}
Update: The exception only occurs when I delete the last (at the end of the list, not the last remaining) record of the data source. However, the deletion operation itself seems to be in order; The correct last item of the data source is getting removed from the underlying data structure (ObservableCollection).
Unfortunately, we cannot currently upgrade our application to .Net 6 due to two other components still relying on .Net 5.