Inheritance: System.Windows.Forms.DataGridViewColumn
Beispiel #1
0
        private void setDataSource(ItemList <Titem> source)
        {
            bool createColumns = true;

            //if (this.source != null) createColumns = false;

            this.source = source;

            if (createColumns)
            {
                Columns.Clear();
                propList.Clear();

                // Add columns to the DataGridView.
                Type theType = typeof(Titem);
                PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(theType).Sort(new GridPositionComparer());

                foreach (PropertyDescriptor pd in pdc)
                {
                    if (pd.IsBrowsable)
                    {
                        // Initialize and add a text box column.
                        DataGridViewColumn column;
                        if (pd.Name.Equals("Id"))
                        {
                            useIdAsRowHeader         = true;
                            RowHeadersWidth          = 23; // 56;
                            idStringFormat.Alignment = System.Drawing.StringAlignment.Far;
                        }
                        else
                        {
                            GridPositionAttribute gridPosition = ((GridPositionAttribute)pd.Attributes[typeof(GridPositionAttribute)]);
                            UnitsAttribute        gridUnits    = ((UnitsAttribute)pd.Attributes[typeof(UnitsAttribute)]);

                            if (gridPosition.Expand)
                            {
                                // Esto se debe modificar para soportar columnas expandibles a
                                // partir de metadatos. Está fijo con StraightFrameProps
                                // porque es la única propiedad que la necesita por el momento.
                                // Será necesario cuando aparezcan más tipos de LineProp's
                                column = new GridViewPopupColumn(new GridViewStraightFrameCell(), new StraightFrameControl());
                            }
                            else if (pd.PropertyType == typeof(JointDOF))
                            {
                                column = new GridViewPopupColumn(new JointDOFControl());
                            }
                            else if (pd.PropertyType == typeof(Joint))
                            {
                                column = new GridViewTextBoxCellTemplateColumn(
                                    new GridViewItemCell(), Canguro.Model.Model.Instance.JointList);
                            }
                            else if (pd.PropertyType == typeof(LineElement))
                            {
                                column = new GridViewTextBoxCellTemplateColumn(
                                    new GridViewItemCell(), Canguro.Model.Model.Instance.LineList);
                            }
                            else if (pd.PropertyType == typeof(AreaElement))
                            {
                                column = new GridViewTextBoxCellTemplateColumn(
                                    new GridViewItemCell(), Canguro.Model.Model.Instance.AreaList);
                            }
                            else if (pd.PropertyType == typeof(AssignedLoads))
                            {
                                column = new GridViewPopupColumn(new AssignedLoadsControl());
                            }
                            else if (pd.PropertyType.Name.Equals("Single[]"))
                            {
                                column = new GridViewSingleArrayColumn();
                            }
                            else if (pd.PropertyType == typeof(float))
                            {
                                column = new GridViewSingleColumn();
                            }
                            else if (pd.PropertyType == typeof(bool))
                            {
                                column = new DataGridViewCheckBoxColumn();
                            }
                            else if (pd.PropertyType == typeof(CardinalPoint))
                            {
                                column = new GridViewPopupColumn(new CardinalPointControl());
                            }
                            else if (pd.PropertyType == typeof(Model.Constraint))
                            {
                                column = new GridViewConstraintComboColumn();
                            }
                            else if (pd.PropertyType == typeof(LineEndOffsets))
                            {
                                column = new GridViewPopupColumn(new EndOffsetsControl());
                            }
                            //else if (pd.PropertyType == typeof(Joint.Bla))
                            //    column = new GridViewLocalizedEnumComboColumn<Joint.Bla>();
                            else
                            {
                                column = new DataGridViewTextBoxColumn();
                            }

                            string units = "";
                            if (gridUnits.Units != Canguro.Model.UnitSystem.Units.NoUnit)
                            {
                                units = " [" + Canguro.Model.Model.Instance.UnitSystem.UnitName(gridUnits.Units) + "]";
                            }
                            column.HeaderText = Culture.Get(pd.DisplayName) + units;
                            column.Name       = pd.Name;
                            //column.ReadOnly = pd.IsReadOnly;
                            column.ValueType = pd.PropertyType;
                            column.Width     = gridPosition.Width;
                            column.Tag       = pd;
                            Columns.Add(column);
                            propList.Add(pd);
                        }
                    }
                }

                AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
                lastUnitSystem      = Canguro.Model.Model.Instance.UnitSystem;
            }

            fillSelectedItems(null, true);
            Enabled = true;
        }