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

前端 未结 6 1362
一向
一向 2021-01-05 08:53

I have a datagrid which gets data like this:

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


        
6条回答
  •  星月不相逢
    2021-01-05 09:41

    This answer is not my own, just the working code example suggested by AnthonyWJones.

    public class MyData //Use class instead of struct
    {
        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"}));
    
    //Create a list of MyData instances
    List myDataItems = new List(); 
    myDataItems.Add(new MyData() { name = "Song1", artist = "MyName", location =     "loc"});
    myDataItems.Add(new MyData() { name = "Song2", artist = "MyName", location =     "loc2"});
    
    //Assign the list to the datagrid's ItemsSource
    dataGrid1.ItemsSource = items;
    

提交回复
热议问题