-2

ItemsSource が ObservableCollection でない場合、DataGridView がセルの編集を許可しないことを理解するのにかなりの時間がかかりました。私はその仮定で正しいですか?

別の DataGridView の SelectedItem のプロパティを ItemsSource として持つ DataGridView があります。残念ながら、その Property は ObservalbeCollection にすることも、それから派生させることもできません。

したがって、ここでの具体的な問題は、ItemsSource が明示的に OberservableCollection でない場合、DataGridView でセルを編集できないことです。そのため、INotifyCollectionChanged インターフェイスが存在することを願っていました。助言がありますか?

前もって感謝します

ジョン

これは、ItemsSource として機能する ViewModel のコードです。

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
}

そして、これは DataGrid の XAML コードです

    <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>
4

1 に答える 1

0

解決策は、IList をカスタム コレクションに明示的に実装することです。動作します!

'EditItem' is not allowed for this viewWPF DataGrid にバインドされた場合のラップされた ObservableCollection のスロー

于 2013-09-21T01:25:52.380 に答える