LINQ-to-XML to DataGridView: Cannot edit fields -- How to fix?

Posted by Pretzel on Stack Overflow See other posts from Stack Overflow or by Pretzel
Published on 2010-04-28T22:29:20Z Indexed on 2010/04/29 3:27 UTC
Read the original article Hit count: 253

Filed under:
|
|
|
|

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?

© Stack Overflow or respective owner

Related posts about linq-to-xml

Related posts about LINQ