EditItem is not allowed for this view linking HashSet to DataGrid



  • Good afternoon.

    The submission contains the following code:

    <Window ...>
        <DataGrid ItemsSource="{Binding Entities, UpdateSourceTrigger=PropertyChanged}" AutoGenerateColumns="False">
            <DataGrid.Columns>
                <DataGridTextColumn Binding="{Binding Text}" Header="Text" Width="*"/>
            </DataGrid.Columns>
        </DataGrid>
    </Window>
    

    Presentation model:

    public class MainVm : BaseVm
    {
        public ICollection<EntityVm> Entities { get; }
    
    public MainVm()
    {
        Entities = new HashSet&lt;EntityVm&gt;
        {
            new EntityVm {Text = "раз" },
            new EntityVm {Text = "два" },
        };
    }
    

    }

    In the row DataGrid (the attempt to add a new element) an exception arises:

    EditItem is not allowed for this view

    How can it be done DataGrid edited?



  • The problem is you're using. HashSetDataGrid Can't add elements to it. Use it. List or ObservableCollection

    UPD

    To answer https://stackoverflow.com/questions/18578254/datagrid-edition-edititem-is-not-allowed-for-this-view-when-bound-to-a-wpf-da This comment was made on en-SO (hereinafter referred to as free translation):

    Reason (this is an addition to List but doesn't work. HashSet) that the connection ItemsSource Ooh. DataGrid to HashSet does not generate a collection that produces IEditableCollectionView♪ For List generated ListCollectionViewwhich operates this interface, which is why it works to connect. List



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2