tags:

views:

31

answers:

0

Hi,

I can easily get the official DataGrid for WPF to work using an ObservableCollection of objects defined like this:

public class Customer : INotifyPropertyChanged
{

    public Customer(int ID, String name)
    {
        this.ID = ID;
        this.name = name;
    }

    public  string name { get; set; }
    public  int ID { get; set; }

    public event PropertyChangedEventHandler  PropertyChanged;

    public void NotifyPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

The column names match the property names etc. But how do I do it so that it will take multiple types? E.g. initially just a Customer but then at some point changed to an ObservableCollection of Orders or something like that, with a different set of properties. If both classes inherit from the same class and you do something like this it obviously doesn't work:

        ObservableCollection<CustomerAndOrderSuperclass> dataSet = new ObservableCollection<CustomerAndOrderSuperclass>();
        dataSet.Add(new Customer(1, "Thomas"));
        dataSet.Add(new Customer(2, "Charles"));
        dataSet.Add(new Customer(3, "Larry"));

Make sense? I think this is a very basic question but it is really confusing me.

Many thanks!