AvaloniaUI / Avalonia.Controls.TreeDataGrid

A combined TreeView/DataGrid for Avalonia.
MIT License
266 stars 54 forks source link

How to make a Flat TreeDataGrid Editable with dynamic values from a dictionary #228

Open sps014 opened 11 months ago

sps014 commented 11 months ago

Hi, I have the following code to add columns , after trying various combination for hours i am still failing to make text editable.

Source = new FlatTreeDataGridSource<EntityViewModel>(Entries);

Source.Columns.Add(new TextColumn<EntityViewModel, string>(nameof(EntityViewModel.Key), x => x.Key, null, new()
{
    IsTextSearchEnabled = true,
    BeginEditGestures =BeginEditGestures.Tap,
    CanUserSortColumn = true
}));

foreach(var c in Languages)
{
    var header = c == string.Empty ? "Neutral" : c;
    Source.Columns.Add(new TextColumn<EntityViewModel, string>(header, x => x.CultureValues[c],null, new()
    {
        IsTextSearchEnabled = true,
        BeginEditGestures = BeginEditGestures.Tap,
        CanUserSortColumn = true,
        TextTrimming= TextTrimming.CharacterEllipsis,
        MaxWidth=new GridLength(300,GridUnitType.Pixel)
    }));
}

here is my class whose items are populated.

public class EntityViewModel
{
    public string? Key { get; set; }
    public Dictionary<string, string?> CultureValues { get; set; } = new();

    public EntityViewModel(Entity entity)
    {
        foreach(var culture in entity.Cultures)
        {
            CultureValues.Add(culture,entity.GetValue(culture));
        }
    }
}

I supose Editing was implemented with https://github.com/AvaloniaUI/Avalonia.Controls.TreeDataGrid/pull/162 .

Thanks.

SvonsySvonson commented 6 months ago

Tried to make Text Column Cells editable in the same way, had the same issue. I got TreeDataGrid NuGet Package 11.0.2

SvonsySvonson commented 6 months ago

I can't make to work even F2 gesture