Error "Object reference not set to an instance of an object." if FlatTreeDataGridSource is recreated with changing edit mode
Wowhere opened this issue · 2 comments
Wowhere commented
Error "Object reference not set to an instance of an object." if FlatTreeDataGridSource is recreated
I`am trying to change EditMode and ReadOnly modes in treeDataGrid in method TreeDataGridInit (code below).
Scenario
- Change mode from ReadOnly to Edit (IsGridEditable = true)
- Change mode from Edit to ReadOnly (IsGridEditable = false)
Result: "Object reference not set to an instance of an object.". Debugger shows that Hint in TemplateColumn is null. Whats wrong, i cant understand how to avoid this error.
Avalonia 11.0.2. Windows 10 Pro 19045.3930
public void TreeDataGridInit()
{
var invisible = new GridLength(0);
if (IsGridEditable)
{
var EditOptions= new TextColumnOptions<Hint>
{
BeginEditGestures = BeginEditGestures.Tap,
IsTextSearchEnabled = true
};
Source = new FlatTreeDataGridSource<Hint>(Hints)
{
Columns =
{
//new TextColumn<Hint, int>("Id", x => x.Id, options: new TextColumnOptions<Hint>{MaxWidth = invisible}),
new TextColumn<Hint, string>("Text", x => x.HintText, (r, v) => r.HintText = v, options: EditOptions),
new TextColumn<Hint, string>("Comment", x => x.Comment, (r, v) => r.Comment = v, options: EditOptions),
new TemplateColumn<Hint>("", new FuncDataTemplate<Hint>((a, e) => DeleteButtonInit(a.Id)))
},
};
IsAddButtonVisible = true;
}
else
{
Source = new FlatTreeDataGridSource<Hint>(Hints)
{
Columns =
{
new TextColumn<Hint, int>("Id", x => x.Id, options: new TextColumnOptions<Hint>{MaxWidth = invisible}),
new TextColumn<Hint, string>("Text", x => x.HintText),
new TextColumn<Hint, string>("Comment", x => x.Comment)
},
};
IsAddButtonVisible = false;
}
Source.Selection = new TreeDataGridCellSelectionModel<Hint>(Source) { };
}
Wowhere commented
Error is avoided by
new TemplateColumn<Hint>("", new FuncDataTemplate<Hint>((a, e) => DeleteButtonInit(a.Id), supportsRecycling: true))
but i cant understand why its working
Wowhere commented
Whatever