Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataGrid 'EditItem' is not allowed for this view when dragging multiple items

I have a datagrid which gets data like this:

    public struct MyData
    {
        public string name { set; get; }
        public string artist { set; get; }
        public string location { set; get; }
    }

    DataGridTextColumn col1 = new DataGridTextColumn();
    col4.Binding = new Binding("name");
    dataGrid1.Columns.Add(col1);
    dataGrid1.Items.Add((new MyData() { name = "Song1", artist = "MyName", location =     "loc"}));
    dataGrid1.Items.Add((new MyData() { name = "Song2", artist = "MyName", location =     "loc2"}));

The problem is- whenever a user tries to edit a cell or drags multiple cells- the app throws an exception:

System.InvalidOperationException was unhandled
Message: 'EditItem' is not allowed for this view.

Why is this? Is it because of the way the data is entered?
Any ideas?
Thanks!

like image 933
amitairos Avatar asked Aug 04 '11 21:08

amitairos


3 Answers

I got this issue when assigning ItemsSource to IEnumerable<T>.

I fixed it by converting the IEnumberable<T> to a List<T> and then assigning that to ItemsSource.

I'm not sure why using IEnumerable caused that issue, but this change fixed it for me.

like image 99
FUR10N Avatar answered Nov 02 '22 18:11

FUR10N


Instead of using a struct use a class instead.

UPDATED ANSWER: Try adding your MyData instances to a List then assigning that list to the DataGrid.ItemsSource

like image 11
AnthonyWJones Avatar answered Nov 02 '22 17:11

AnthonyWJones


If you use datagrid DataGridCheckBoxColumn you need to set <Setter Property="IsEditing" Value="true" /> on check box column. See this: https://stackoverflow.com/a/12244451/1643201

like image 1
TotPeRo Avatar answered Nov 02 '22 17:11

TotPeRo