示例#1
0
        // customize the columns of a C1FlexGrid control
        // use dynamic type in order to avoid dependencies.
        static void CustomizeFlexGrid(dynamic flex, Type entType, EntityDataSource entDataSource)
        {
            // configure columns
            foreach (dynamic c in flex.Cols)
            {
                // if the column is a key, make it read-only
                var pi = entType.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 = entDataSource.GetLookupDictionary(type);
                    }
                }
            }
        }
示例#2
0
        // customize the columns of a DataGridView
        static void CustomizeDataGridView(DataGridView dgv, Type entType, EntityDataSource entDataSource)
        {
            // configure columns
            for (int colIndex = 0; colIndex < dgv.Columns.Count; colIndex++)
            {
                // get column
                var c = dgv.Columns[colIndex];

                // if the column is a key, make it read-only
                var pi = entType.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 = entDataSource.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";
                            dgv.Columns.RemoveAt(colIndex);
                            dgv.Columns.Insert(colIndex, col);
                        }
                    }
                }
            }
        }