I'm trying to add items programmaticly to a DataGrid and letting the user edit the data. However, I keep getting "EditItem is not allowed for this view" errors when trying to edit data. I tried making the class I'm adding an ObservableCollection but it doesn't seem to change the errors. These are snippets of my code:
XAML:
<DataGrid x:Name="DataGridExample" HorizontalAlignment="Left" Margin="35,40,0,0" VerticalAlignment="Top" Height="220" Width="525" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Path=Name}" ClipboardContentBinding="{x:Null}" Header="Filename"/>
<DataGridTextColumn Binding="{Binding Path=Prefix}" ClipboardContentBinding="{x:Null}" Header="Prefix"/>
<DataGridCheckBoxColumn Binding="{Binding Path=Sign}" ClipboardContentBinding="{x:Null}" Header="Sign"/>
<DataGridCheckBoxColumn Binding="{Binding Path=Bin}" ClipboardContentBinding="{x:Null}" Header="Bin"/>
<DataGridTextColumn Binding="{Binding Path=FolderPath}" ClipboardContentBinding="{x:Null}" Header="Folderpath"/>
</DataGrid.Columns>
</DataGrid>
MainWindowClass adding the item:
Example newExample = new Example() { FolderPath = folderpath, Name = foldername, Prefix = foldername, Bin = false, Sign = false };
DataGridExample.Items.Add(newExample);
Example class:
public class Example : ObservableCollection<Example>
{
public string FolderPath { get; set; }
public string Name { get; set; }
public string Prefix { get; set; }
public bool Sign { get; set; }
public bool Bin { get; set; }
public override string ToString()
{
return Name;
}
}