728x90

GridControl 에 ExpandObject 바인딩 하기위해서는 먼저 이전 포스팅에서 ExpandObject 사용하는 방법을 참고합니다

2022.09.15 - [C#] - [C#] ExpandoObject 사용하기

MainWindow.xaml

<dxg:GridControl
    Grid.Row="4"
    Height="300"
    AutoGenerateColumns="AddNew"
    ItemsSource="{Binding Dynamicitems}"
    SelectionMode="Cell">
    <dxg:GridControl.View>
        <dxg:TableView
            HeaderHorizontalAlignment="Center"
            NavigationStyle="Cell"
            ShowGroupPanel="False" />
    </dxg:GridControl.View>
</dxg:GridControl>

MainViewModel.cs

private ObservableCollection<object> dynamicitems;

public ObservableCollection<object> Dynamicitems
{
    get
    {
        if (this.dynamicitems == null)
        {
            this.dynamicitems = new ObservableCollection<object>();
        }

        return this.dynamicitems;
    }
    set
    {
        this.dynamicitems = value;
        OnPropertyChanged();
    }
}


List<(int ID, string NAME)> datas = new List<(int, string)>() { (1, "A"), (2, "B"), (3, "C") };

foreach (var data in datas)
{
    dynamic expando = new ExpandoObject();

    AddProperty(expando, "ID", data.ID);
    AddProperty(expando, "Name", data.NAME);

    Dynamicitems.Add(expando);
}

결과

소스
https://github.com/kei-soft/KJunBlog/tree/master/Wpf.DevGridTest

728x90
Posted by kjun.kr
,