Beispiel #1
0
 private void GridView_ColumnWidthChanged(object sender, DataGridViewColumnEventArgs e)
 {
     if (this.DataContext != null)
     {
         var view = (BAL.Business.View) this.DataContext;
         BAL.Types.Column column = null;
         foreach (BAL.Types.Column col in view.VisibleColumns.GetVisible())
         {
             if (col.Name == e.Column.Name)
             {
                 column = col;
                 break;
             }
         }
         if (column != null)
         {
             column.Width = e.Column.Width;
         }
     }
 }
Beispiel #2
0
        protected virtual DataGridViewColumn CreateGridColumn(object columnInfo)
        {
            BAL.Types.Column info = columnInfo as BAL.Types.Column;
            if (info != null)
            {
                DataGridViewColumn column = null;
                Type ut       = Nullable.GetUnderlyingType(info.Type);
                Type dataType = ut ?? info.Type;
                switch (dataType.Name.ToLower())
                {
                case "boolean":
                    column = new BAL.Forms.Controls.GridViewCheckBoxColumn();
                    break;

                default:
                    column = new DataGridViewTextBoxColumn();
                    break;
                }
                column.Name             = info.Name;
                column.HeaderText       = info.HeaderText;
                column.DataPropertyName = info.PropertyDescriptorPath != null?info.PropertyDescriptorPath.ToString() : info.PropertyPath.ToString();

                column.Width    = info.Width > 0 ? info.Width : 100;
                column.SortMode = DataGridViewColumnSortMode.Automatic;
                column.ReadOnly = info.ReadOnly;
                //column.SortMode = DataGridViewColumnSortMode.Programmatic;
                column.ToolTipText = info.PropertyDescriptorPath != null?info.PropertyDescriptorPath.ToString() : info.PropertyPath.ToString();

                switch (info.TextAlign)
                {
                case Types.TextAlign.None:
                case Types.TextAlign.Left:
                    column.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
                    break;

                case Types.TextAlign.Right:
                    column.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                    break;

                case Types.TextAlign.Center:
                    column.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                    break;
                }
                switch (info.HeaderTextAlign)
                {
                case Types.TextAlign.None:
                case Types.TextAlign.Left:
                    column.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleLeft;
                    break;

                case Types.TextAlign.Right:
                    column.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight;
                    break;

                case Types.TextAlign.Center:
                    column.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
                    break;
                }

                if (!string.IsNullOrEmpty(info.Format))
                {
                    column.DefaultCellStyle.Format = info.Format;
                }

                return(column);
            }
            return(null);
        }