0

I just stumbled upon a behavior of the DataGrid in WPF and frankly I don't know if I did something wrong or its the standard behavior of the WPF DataGrid.

So I have an interface, let's call it IItem. IItem has couple of properties (Name, Active, Timestamp). This interface inherits from an other interface lets call it IBaseItem. IBaseItem also has properties (Id, Selected, Active, Timestamp). So I would expect when I create a DataGrid in XAML with AutoGenerateColumns=true and the binding source is a List<IItem> then It would generate the Id and the Selected columns as well.

Instead it only generates the Name, Active and Timestamp properties as columns. And the Name is not editable (although it has a setter property) but Active is.

public interface IBaseItem : INotifyPropertyChanged
{
    bool Selected { get; set; }
    int Id { get; }
    bool Active { get; set; }
            DateTime Timestamp { get; set;}
}

public interface IItem: IBaseItem, IEditableObject
{
    string Name { get; set; }
    new bool Active { get; set; }
    new DateTime Timestamp { get; }
}

But if I break the inheritance chain and make the IItem as an individual interface then voila the Name become editable.

I don't get why the inheritance is messing things up. Can anyone enlighten me?

jv42
  • 8,521
  • 5
  • 40
  • 64
JahManCan
  • 601
  • 3
  • 8
  • 19
  • Meanwhile I found this on msdn: http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.autogeneratecolumns.aspx, look at remarks. Is this corresponding with my problem? – JahManCan Mar 13 '12 at 12:10
  • Please show actual class where in implement these interfaces. I thought it might be isReadOnly on the DataGrid but idReadOnly=false will still Autogenerate a column with no setter. – paparazzo Mar 13 '12 at 14:46
  • Please post `IBaseItem` code. Also show the class that implements this. I tried all the interfaces from your sample information with `AutogenerateColumns` as true and to me `Name` is perfectly editable, along with all others in the inheritance mode. – WPF-it Mar 14 '12 at 10:37

0 Answers0