开发者

Dynamic Data binding in WPF Devx GridControl

I'm working on a WPF application ( MVVM) and using the DevExpress GridCOntrol. I need to create a generic screen to display data from multiple tables ( displaying one at a time) which have reference data. So the grid control needs to bind to a dataset which can contain differnt number of columns depending on the table being queries.

Questions:

1) What type of object should my data access layer return? At present I can only think of a Dataset /DataTable.. is there any other alternative as I really wa开发者_JAVA技巧nt to avoid using datasets and datatables .. a dictionay perhaps ? Whats the best way to return such data ?

2) In case I return something besides a Dataset/DataTable , how do I bind my GridControl with this dynamic data collection ?

Thanks a lot.


I've used an approach similar to this in the past with success

http://www.paulstovell.com/dynamic-datagrid

public class Property : INotifyPropertyChanged
{
    public Property(string name, object value)
    {
        Name = name;
        Value = value;
    }

    public string Name { get; private set; }
    public object Value { get; set; }
}


public class Record
{
    private readonly ObservableCollection<Property> properties = new ObservableCollection<Property>();

    public Record(params Property[] properties)
    {
        foreach (var property in properties)
            Properties.Add(property);
    }

    public ObservableCollection<Property> Properties
    {
        get { return properties; }
    }
}
<DataGrid 
   Name="dataGrid" 
   AutoGenerateColumns="false" 
   ItemsSource="{Binding Path=Records}"/>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜