This must be very simple, but I seem to be missing something. I've searched around for a few hours without coming across anything that can resolve my problem. The issue is that although I can assign my LINQ query to a WPF DataGrid, when I try to edit one of the DataGrid's values I get the following error:
System.InvalidOperationException was unhandled Message='EditItem' is not allowed for this view. Source=PresentationFramework StackTrace: at System.Windows.Controls.ItemCollection.System.ComponentModel.IEditableCollectionView.EditItem(Object item) at System.Windows.Controls.DataGrid.EditRowItem(Object rowItem) at System.Windows.Controls.DataGrid.OnExecutedBeginEdit(ExecutedRoutedEventArgs e) at System.Windows.Controls.DataGrid.OnExecutedBeginEdit(Object sender, ExecutedRoutedEventArgs e) at System.Windows.Input.CommandBinding.OnExecuted(Object sender, ExecutedRoutedEventArgs e)
The XAML for my DataGrid looks like this:
<DataGrid AutoGenerateColumns="False" EnableRowVirtualization="True" Height="565" HorizontalAlignment="Left" Margin="6,92,0,0" Name="translatedStringsDataGrid1" RowDetailsVisibilityMode="VisibleWhenSelected" VerticalAlignment="Top" Width="602">
<DataGrid.Columns>
<DataGridTextColumn x:Name="stringsIDColumn2" Binding="{Binding Path=StringsID}" Header="Strings Name" Width="SizeToHeader" />
<DataGridTextColumn x:Name="translatedStringsValueColumn1" Binding="{Binding Path=TranslatedStringsValue}" Header="Translated Strings Value" Width="SizeToHeader" />
</DataGrid.Columns>
</DataGrid>
I am doing a LINQ query in the SelectedChange event of a ComboBox like this:
private void cbSelectLang_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var query = from o in _context.TranslatedStrings.Local
where o.LanguagesID == cbSelectLang.SelectedIndex + 1
join r in _context.Strings.Local on o.StringsID equals r.StringsID into SubSet2
from s in SubSet2.DefaultIfEmpty()
select new { StringsID = s.StringsName, TranslatedStringsValue = o.TranslatedStringsValue };
this.translatedStringsDataGrid1.ItemsSource = query;
}
I'm using "POCO entities" if anybody thinks there is an easier way of accomplishing this. I really do get the feeling that I'm missing something very basic and obvious, if anybody would be so kind as to point it out to me! :-)
Many thanks.