0

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 want 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.

1 Answer 1

4

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}"/>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.