拖动多个项目时,此视图不允许 DataGrid 'EditItem' [英] 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 未处理
消息:此视图不允许使用EditItem".
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!
推荐答案
不要使用 struct
,而是使用 class
.
Instead of using a struct
use a class
instead.
更新的答案:尝试将您的 MyData 实例添加到列表中,然后将该列表分配给 DataGrid.ItemsSource
UPDATED ANSWER: Try adding your MyData instances to a List then assigning that list to the DataGrid.ItemsSource
这篇关于拖动多个项目时,此视图不允许 DataGrid 'EditItem'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!