// customize the columns of a C1FlexGrid control
        // use dynamic type in order to avoid dependencies.
        static void CustomizeFlexGrid(dynamic flex, Type entityType, EntityDataSource datasource)
        {
            // configure columns
            foreach (dynamic c in flex.Cols)
            {
                // if the column is a key, make it read-only
                var pi = entityType.GetProperty(c.Name);
                if (pi != null)
                {
                    var atts = pi.GetCustomAttributes(typeof(EdmScalarPropertyAttribute), false);
                    if (atts.Length > 0)
                    {
                        var att = atts[0] as EdmScalarPropertyAttribute;
                        if (att.EntityKeyProperty)
                        {
                            c.AllowEditing = false;
                        }
                    }

                    // if the column holds entities, give it a data map
                    var type = pi.PropertyType;
                    if (!type.IsPrimitive)                    // typeof(EntityObject).IsAssignableFrom(type))
                    {
                        c.DataMap = datasource.GetLookupDictionary(type);
                    }
                }
            }
        }
        // customize the columns of a DataGridView
        static void CustomizeDataGridView(DataGridView gridview, Type entityType, EntityDataSource datasource)
        {
            // configure columns
            for (int colIndex = 0; colIndex < gridview.Columns.Count; colIndex++)
            {
                // get column
                var c = gridview.Columns[colIndex];

                // if the column is a key, make it read-only
                var pi = entityType.GetProperty(c.DataPropertyName);
                if (pi != null)
                {
                    var atts = pi.GetCustomAttributes(typeof(EdmScalarPropertyAttribute), false);
                    if (atts.Length > 0)
                    {
                        var att = atts[0] as EdmScalarPropertyAttribute;
                        if (att.EntityKeyProperty)
                        {
                            c.ReadOnly = true;
                        }
                    }

                    // if the column holds entities, give it a data map
                    var type = pi.PropertyType;
                    if (!type.IsPrimitive)
                    //if (typeof(EntityObject).IsAssignableFrom(type))
                    {
                        var map = datasource.GetLookupDictionary(type);
                        if (map != null)
                        {
                            var col = new DataGridViewComboBoxColumn();
                            col.HeaderText       = c.HeaderText;
                            col.DataPropertyName = c.DataPropertyName;
                            col.Width            = c.Width;
                            col.DefaultCellStyle = c.DefaultCellStyle;
                            col.DataSource       = map;
                            col.ValueMember      = "Key";
                            col.DisplayMember    = "Value";
                            gridview.Columns.RemoveAt(colIndex);
                            gridview.Columns.Insert(colIndex, col);
                        }
                    }
                }
            }
        }