0

I'm working on a Silverlight project for CRM 2011. I have an EntityCollection resulting from a QueryExpression and i need to display these entities in a datagrid.

I have checked several solutions online, but none is working.

I would appreciate your help.

user1927272
  • 27
  • 1
  • 6

2 Answers2

1

Check it once. It will Work

    public DataTable GetDataTable()
    {

        DataTable dTable = new DataTable();

        int iElement = 0;
        for (iElement = 0; iElement < ent.Entities[0].Attributes.Count; iElement++)
        {

            string ColName = ent.Entities[0].Attributes.Keys.ElementAt(iElement);
            dTable.Columns.Add(ColName);

        }
        for (int y = 0; y < ent.Entities.Count - 1; y++)
        {
            DataRow drow = dTable.NewRow();
            for (iElement = 0; iElement < ent.Entities[y].Attributes.Count; iElement++)
            {
                string ColNam = ent.Entities[y].Attributes.Keys.ElementAt(iElement);
                drow[ColNam] = ent.Entities[y].Attributes.Values.ElementAt(iElement);
            }
            dTable.Rows.Add(drow);
        }

        return dTable;

    }
0

I believe that easiest way is to convert your EntityCollection elements to some typed objects or DataTable and bind it to datagrid. Other approach is to use OData, get data through it and bind this collection to datagrid.

Andrew Butenko
  • 5,048
  • 1
  • 14
  • 13