-2

it took me quite some time to figure out that a DataGridView wont allow editing Cells if the ItemsSource is not an ObservableCollection. Am I right in that assumption?

I have a DataGridView having a Property of another DataGridView's SelectedItem as ItemsSource. Unfortunatly that Property can not be a ObservalbeCollection or derived from it.

So my concrete problem here is, that the DataGridView wont allow me to edit Cells if its ItemsSource is not explicitly a OberservableCollection. I hoped, that the INotifyCollectionChanged Interface was there for that reason. Any suggestions?

Thanks in advance

John

This is the code for my ViewModel which serves as ItemsSource

public class NdfCollection : NdfValueWrapper, IList<NdfValueWrapper>, INotifyCollectionChanged
{
    private readonly ObservableCollection<NdfValueWrapper> _innerList = new ObservableCollection<NdfValueWrapper>();

    public NdfCollection(long offset)
        : base(NdfType.List, offset)
    {

    }

    public NdfCollection(IEnumerable<NdfValueWrapper> list, long offset)
        : this(offset)
    {
        if (list != null)
            foreach (NdfValueWrapper wrapper in list)
                InnerList.Add(wrapper);
    }

    public ObservableCollection<NdfValueWrapper> InnerList
    {
        get { return _innerList; }
    }

    // Implementation of the Interfaces not pasted in here
}

And this is my XAML code for the DataGrid

    <DataGrid Grid.Row="1" MaxHeight="400" ItemsSource="{Binding Path=SelectedItem.Value,  ElementName=propGrid}" 
                  IsSynchronizedWithCurrentItem="True"
                  CanUserResizeRows="False"
                  CanUserAddRows="False"  
                  CanUserDeleteRows="False" 
                  AutoGenerateColumns="False"
                  SelectionMode="Single"
                  SelectionUnit="CellOrRowHeader" IsReadOnly="False">
        <DataGrid.Columns>
            <DataGridTextColumn Binding="{Binding Path=Type}" Header="Type" IsReadOnly="True" Width="*" />
            <!--<DataGridTextColumn Binding="{Binding}" Header="Biniary Value" IsReadOnly="False" Width="*" />-->
            <DataGridTemplateColumn Header="Value" IsReadOnly="False" Width="*" CellEditingTemplateSelector="{DynamicResource editingControlTemplateSelector}" >
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding}" />
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>
        </DataGrid.Columns>
    </DataGrid>
Ian
  • 305
  • 3
  • 8

1 Answers1

0

The solution is to explicitly implement IList to the custom Collection. Works!

Wrapped ObservableCollection throwing 'EditItem' is not allowed for this view when bound to a WPF DataGrid

Community
  • 1
  • 1
Ian
  • 305
  • 3
  • 8