Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
100
hierarchical xamdatagrid, updating childrows
posted

Hi;

we bound a xamDatagrid to a ViewModel like so:

using System;

public class ClassA: ObservableModel
{
    public string Id { get; set; }
    public ObservableCollection<ClassB> ListB { get; set; }
}

public class ClassB : ObservableModel
{    public string Id { get; set; }
    public ObservableCollection<ClassC> ListC { get; set; }
}

public class ClassC : ObservableModel
{
    public string Id { get; set; }
}

public class ViewModel
{
    public ObservableCollection<ClassA> ListA { get; set; }
    public ViewModel()
    {
        this.ListA = new ObservableCollection<ClassA>();
    }
}

<igDP:XamDataGrid Name = "xamDataGrid1" DataSource="{Binding ListA}"                >

To edit instances from type classC we have a modal Dialog. The Dialog starts by doubleclick in the corresponding Row of the grid. If the Dialog Returns with true, the datas are stored in DB. To refresh the Grid we use following Code

void refeshItem(string Id)
{
    // get the new datas from db
    var datas = await getDatasByIdFromDbASync(Id).ConfigureAwait(true);
    ClassC existC = null;
    ClassB existB = null;
    int indexOfC = -1;
    // look for old item
    foreach (var a in this.ListA)
    {
        foreach (var b in a.ListB)
        {
            existC = b.ListC.FirstOrDefault(p => p.Id == datas.Id);
            if (null != existC)
            {
                existB = b;
                indexOfC = b.ListC.IndexOf(existC);
                break;
            }
        }
        if (null != existC) break;
    }
    if (indexOfC == -1) return;
    if (null == existB) return;
    if (null == existC) return;

    // Invoke the Collection changed event with Remove: OK
    existB.ListC[indexOfC] = datas;
    datas.OnPropertyChanged();
}

But the Datarecords are not refreshed. Any suggestions?

Regards Torsten