LINQ-to-XML to DataGridView: Cannot edit fields -- How to fix?
- by Pretzel
I am currently doing LINQ-to-XML and populating a DataGridView with my query just fine. The trouble I am running into is that once loaded into the DataGridView, the values appear to be Un-editable (ReadOnly). Here's my code:
var barcodes = (from src in xmldoc.Descendants("Container")
where src.Descendants().Count() > 0
select
new
{
Id = (string)src.Element("Id"),
Barcode = (string)src.Element("Barcode"),
Quantity = float.Parse((string)src.Element("Quantity").Attribute("value"))
}).Distinct();
dataGridView1.DataSource = barcodes.ToList();
I read somewhere that the "DataGridView will be in ReadOnly mode when you use Anonymous types." But I couldn't find an explanation why or exactly what to do about it.
Any ideas?