public override int GetPreferredWidth(DataGridViewAutoSizeColumnMode autoSizeColumnMode, bool fixedHeight) { int preferredWidth = base.GetPreferredWidth(autoSizeColumnMode, fixedHeight); if (AdditionalColumnWidth != null) preferredWidth += AdditionalColumnWidth(this); return preferredWidth; }
private void ComboBoxColumn(DataGridView grid, DataGridViewComboBoxColumn column, DataGridViewContentAlignment alignment, string cellformat, string colname, string headertext, string propertyname, int orderindex, DataGridViewAutoSizeColumnMode mode, object datasource, Color color, bool visibile = true, bool isreadonly = false, int width = 100) { column.DefaultCellStyle.Alignment = alignment; column.HeaderCell.Style.Alignment = alignment; column.HeaderCell.Style.ForeColor = color; column.SortMode = DataGridViewColumnSortMode.NotSortable; column.DefaultCellStyle.Format = cellformat; column.Name = colname; column.HeaderText = headertext; column.Visible = visibile; column.ReadOnly = isreadonly; column.Resizable = DataGridViewTriState.False; column.DataPropertyName = propertyname; column.AutoSizeMode = mode; column.Frozen = false; column.MinimumWidth = 5; column.Width = width; column.DisplayIndex = orderindex; column.ValueMember = "Index"; column.DisplayMember = "FileExtension"; column.DataSource = datasource; grid.Columns.Add(column); }
static public DataGridViewComboBoxColumn AddDgvComboBox(object _DataSource, string _ValueMember, string _DisplayMember, string _DataPropertyName, string _HeaderText, int _Width, bool _Visible = true, bool _ReadOnly = false, DgvAlign _Alignment = DgvAlign.N, DataGridViewColumnSortMode _Sort = DataGridViewColumnSortMode.Automatic, DataGridViewAutoSizeColumnMode _AutoSizeMode = DataGridViewAutoSizeColumnMode.NotSet, string _Name = "") { var col = new DataGridViewComboBoxColumn { DataSource = _DataSource, ValueMember = _ValueMember, DisplayMember = _DisplayMember, Name = (_Name == "" ? _DataPropertyName : _Name), DataPropertyName = _DataPropertyName, HeaderText = _HeaderText, DefaultCellStyle = { Alignment = (DataGridViewContentAlignment)_Alignment }, ReadOnly = _ReadOnly, Visible = _Visible, SortMode = _Sort, AutoSizeMode = _AutoSizeMode, Width = _Width }; return(col); }
/// <summary> /// Добавить столбец /// </summary> /// <param name="text">Текст для заголовка столбца</param> /// <param name="bRead">флаг изменения пользователем ячейки</param> /// <param name="nameCol">имя столбца</param> public void AddColumn(string txtHeader, bool bRead, string nameCol) { DataGridViewContentAlignment alignText = DataGridViewContentAlignment.NotSet; DataGridViewAutoSizeColumnMode autoSzColMode = DataGridViewAutoSizeColumnMode.NotSet; try { HDataGridViewColumn column = new HDataGridViewColumn() { m_bCalcDeny = false }; alignText = DataGridViewContentAlignment.MiddleLeft; autoSzColMode = DataGridViewAutoSizeColumnMode.Fill; column.ReadOnly = bRead; column.Name = nameCol; column.HeaderText = txtHeader; column.DefaultCellStyle.Alignment = alignText; column.AutoSizeMode = autoSzColMode; column.Tag = -1; // заголовок столбца -1 Columns.Add(column as DataGridViewTextBoxColumn); } catch (Exception e) { Logging.Logg().Exception(e, @"DGVAutoBook::AddColumn () - ...", Logging.INDEX_MESSAGE.NOT_SET); } }
/// <summary> /// Добавить столбец /// </summary> /// <param name="text">Текст для заголовка столбца</param> /// <param name="bRead"></param> public void AddColumn(string txtHeader, bool bRead, string nameCol) { DataGridViewContentAlignment alignText = DataGridViewContentAlignment.NotSet; DataGridViewAutoSizeColumnMode autoSzColMode = DataGridViewAutoSizeColumnMode.NotSet; //DataGridViewColumnHeadersHeightSizeMode HeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; try { HDataGridViewColumn column = new HDataGridViewColumn() { m_bCalcDeny = false }; alignText = DataGridViewContentAlignment.MiddleRight; autoSzColMode = DataGridViewAutoSizeColumnMode.Fill; //column.Frozen = true; column.ReadOnly = bRead; column.Name = nameCol; column.HeaderText = txtHeader; column.DefaultCellStyle.Alignment = alignText; column.AutoSizeMode = autoSzColMode; Columns.Add(column as DataGridViewTextBoxColumn); } catch (Exception e) { Logging.Logg().Exception(e, @"DataGridViewAutoBookYearlyPlan::AddColumn () - ...", Logging.INDEX_MESSAGE.NOT_SET); } }
private void TextBoxColumn(DataGridView grid, DataGridViewTextBoxColumn column, DataGridViewContentAlignment alignment, string cellformat, string colname, string headertext, string propertyname, int orderindex, DataGridViewAutoSizeColumnMode mode, Color color, bool visibile = true, bool isreadonly = false, int width = 100, int maxlength = 32767) { column.DefaultCellStyle.Alignment = alignment; column.HeaderCell.Style.Alignment = alignment; column.HeaderCell.Style.ForeColor = color; column.SortMode = DataGridViewColumnSortMode.NotSortable; column.DefaultCellStyle.Format = cellformat; column.Name = colname; column.HeaderText = headertext; column.Visible = visibile; column.MaxInputLength = maxlength; column.ReadOnly = isreadonly; column.Resizable = DataGridViewTriState.False; column.DataPropertyName = propertyname; column.AutoSizeMode = mode; column.Frozen = false; column.MinimumWidth = 5; column.Width = width; column.DisplayIndex = orderindex; grid.Columns.Add(column); }
public static void AutoColumnSize(DataGridView drv, DataGridViewAutoSizeColumnMode mode) { var displayedIndex = new List <int>(); for (var i = 0; i < drv.Columns.Count; ++i) { for (var j = 0; j < drv.Columns.Count; ++j) { if (drv.Columns[j].DisplayIndex == i && drv.Columns[j].Visible) { displayedIndex.Add(j); } } } for (var i = 0; i < displayedIndex.Count - 1; ++i) { var index = displayedIndex[i]; var column = drv.Columns[index]; column.AutoSizeMode = mode; var widthCol = column.Width; column.AutoSizeMode = DataGridViewAutoSizeColumnMode.NotSet; column.Width = widthCol; } }
public static void ColumnsAutoSize(DataGridView grid, DataGridViewAutoSizeColumnMode mode) { foreach (DataGridViewColumn col in grid.Columns) { col.AutoSizeMode = mode; } }
public DGVTemplateColumn(string name, string header, int width, DataGridViewAutoSizeColumnMode autoSizeMode, bool visible) : this() { Name = name; Header = header; Width = width; AutoSizeMode = autoSizeMode; Visible = visible; }
public DgvColAttribute(string colName, int index, bool isReadonly, DataGridViewAutoSizeColumnMode mode, string format) { Name = colName; Index = index; ReadOnly = isReadonly; Mode = mode; Format = format; }
public override void ReSizeDataGridView(DataGridViewAutoSizeColumnMode type) { for (int i = 0; i < dgvTieuThu.Columns.Count; i++) { // set size display dgvTieuThu.Columns[i].AutoSizeMode = type; // set text color header } }
void setToAutoFill(DataGridView dgv) { DataGridViewAutoSizeColumnMode mode = DataGridViewAutoSizeColumnMode.Fill; for (int j = 0; j < dgv.Columns.Count; j++) { dgv.Columns[j].AutoSizeMode = mode; } }
private void AddColumn(string name, bool readOnly, DataGridViewAutoSizeColumnMode sizeMode) { int index = this.Columns.Add(name, name); this.Columns[index].ReadOnly = readOnly; this.Columns[index].Resizable = DataGridViewTriState.False; this.Columns[index].SortMode = DataGridViewColumnSortMode.NotSortable; this.Columns[index].AutoSizeMode = sizeMode; }
public void AutosizeColumnMode(string name, DataGridViewAutoSizeColumnMode mode) { int col = this.GetColumn(name); if (col < 0) { return; } this.Columns[col].AutoSizeMode = mode; }
public static void setDataGridViewAutoSizeMode(DataGridView dgv, DataGridViewAutoSizeColumnMode mode = DataGridViewAutoSizeColumnMode.NotSet) { dgv.RowHeadersVisible = false; foreach (DataGridViewColumn dgvc in dgv.Columns) { dgvc.AutoSizeMode = mode; dgvc.Resizable = DataGridViewTriState.True; dgvc.SortMode = DataGridViewColumnSortMode.NotSortable; } }
public override int GetPreferredWidth(DataGridViewAutoSizeColumnMode autoSizeColumnMode, bool fixedHeight) { int preferredWidth = base.GetPreferredWidth(autoSizeColumnMode, fixedHeight); if (AdditionalColumnWidth != null) { preferredWidth += AdditionalColumnWidth(this); } return(preferredWidth); }
private void AddCheckboxColumn(string name, DataGridViewAutoSizeColumnMode sizeMode) { int index = this.Columns.Add(new DataGridViewCheckBoxColumn()); this.Columns[index].HeaderText = name; this.Columns[index].ReadOnly = false; this.Columns[index].Resizable = DataGridViewTriState.False; this.Columns[index].SortMode = DataGridViewColumnSortMode.NotSortable; this.Columns[index].AutoSizeMode = sizeMode; }
public DataGridViewColumn(DataGridViewCell cellTemplate) : base() { _fillWeight = DefaultFillWeight; _usedFillWeight = DefaultFillWeight; Thickness = ScaleToCurrentDpi(DefaultWidth); MinimumThickness = ScaleToCurrentDpi(DefaultMinColumnThickness); _name = string.Empty; _displayIndex = -1; CellTemplate = cellTemplate; _autoSizeMode = DataGridViewAutoSizeColumnMode.NotSet; }
public DataGridViewColumn(DataGridViewCell cellTemplate) : base() { fillWeight = DATAGRIDVIEWCOLUMN_defaultFillWeight; usedFillWeight = DATAGRIDVIEWCOLUMN_defaultFillWeight; Thickness = ScaleToCurrentDpi(DATAGRIDVIEWCOLUMN_defaultWidth); MinimumThickness = ScaleToCurrentDpi(DATAGRIDVIEWCOLUMN_defaultMinColumnThickness); name = string.Empty; displayIndex = -1; CellTemplate = cellTemplate; autoSizeMode = DataGridViewAutoSizeColumnMode.NotSet; }
public DataGridViewColumn(DataGridViewCell cellTemplate) : base() { this.fillWeight = DATAGRIDVIEWCOLUMN_defaultFillWeight; this.usedFillWeight = DATAGRIDVIEWCOLUMN_defaultFillWeight; this.Thickness = ScaleToCurrentDpi(DATAGRIDVIEWCOLUMN_defaultWidth); this.MinimumThickness = ScaleToCurrentDpi(DATAGRIDVIEWCOLUMN_defaultMinColumnThickness); this.name = string.Empty; this._bandIsRow = false; this.displayIndex = -1; this.cellTemplate = cellTemplate; this.autoSizeMode = DataGridViewAutoSizeColumnMode.NotSet; }
/// <include file='doc\DataGridViewColumn.uex' path='docs/doc[@for="DataGridViewColumn.DataGridViewColumn3"]/*' /> public DataGridViewColumn(DataGridViewCell cellTemplate) : base() { this.fillWeight = DATAGRIDVIEWCOLUMN_defaultFillWeight; this.usedFillWeight = DATAGRIDVIEWCOLUMN_defaultFillWeight; this.Thickness = DATAGRIDVIEWCOLUMN_defaultWidth; this.MinimumThickness = DATAGRIDVIEWCOLUMN_defaultMinColumnThickness; this.name = String.Empty; this.bandIsRow = false; this.displayIndex = -1; this.cellTemplate = cellTemplate; this.autoSizeMode = DataGridViewAutoSizeColumnMode.NotSet; }
private T CreateDataGridViewColumn <T>(bool readOnly, string dataPropertyName, string headerText, DataGridViewAutoSizeColumnMode autoSizeMode) where T : DataGridViewColumn, new() { var column = new T { ReadOnly = readOnly, DataPropertyName = dataPropertyName, HeaderText = headerText, AutoSizeMode = autoSizeMode }; return(column); }
public DataGridViewColumn(DataGridViewCell cellTemplate) { this.boundColumnIndex = -1; this.dataPropertyName = string.Empty; this.fillWeight = 100f; this.usedFillWeight = 100f; base.Thickness = 100; base.MinimumThickness = 5; this.name = string.Empty; base.bandIsRow = false; this.displayIndex = -1; this.cellTemplate = cellTemplate; this.autoSizeMode = DataGridViewAutoSizeColumnMode.NotSet; }
public void StoreSettings(DataGridView dataGridView1, int columnsIndex) { autoSizeColumnMode = dataGridView1.Columns[columnsIndex].AutoSizeMode; cellStyle = dataGridView1.Columns[columnsIndex].DefaultCellStyle; defaultHeaderCellType = dataGridView1.Columns[columnsIndex].DefaultHeaderCellType; frozen = dataGridView1.Columns[columnsIndex].Frozen; headerText = dataGridView1.Columns[columnsIndex].HeaderText; minimumWidth = dataGridView1.Columns[columnsIndex].MinimumWidth; name = dataGridView1.Columns[columnsIndex].Name; readOnly = dataGridView1.Columns[columnsIndex].ReadOnly; resizable = dataGridView1.Columns[columnsIndex].Resizable; sortMode = dataGridView1.Columns[columnsIndex].SortMode; width = dataGridView1.Columns[columnsIndex].Width; }
private DataGridViewAutoSizeColumnMode CheckButtons() { DataGridViewAutoSizeColumnMode result = DataGridViewAutoSizeColumnMode.None; if (!toolStripButtonColumnId.Checked && !toolStripButtonColumnProject.Checked && !toolStripButtonColumnAdditionalFields.Checked && !toolStripButtonStatus.Checked) { result = DataGridViewAutoSizeColumnMode.Fill; } return(result); }
public override void ReSizeDataGridView(DataGridViewAutoSizeColumnMode type) { try { for (int i = 0; i < dgvGia.ColumnCount; i++) { //auto fill column dgvGia.Columns[i].AutoSizeMode = type; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public override void ReSizeDataGridView(DataGridViewAutoSizeColumnMode type) { try { for (int i = 0; i < dgvKhachHang.Columns.Count; i++) { // set size display dgvKhachHang.Columns[i].AutoSizeMode = type; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public static void AgregarColumna(this DataGridView dtgv, string nombre, string textoCabecera, Type tipo, int ancho = 0, bool soloLectura = false, bool visible = true, string formato = "", DataGridViewContentAlignment alignment = DataGridViewContentAlignment.MiddleLeft, DataGridViewAutoSizeColumnMode autoSizeColumnMode = DataGridViewAutoSizeColumnMode.None) { int index = dtgv.Columns.Add(nombre, textoCabecera); dtgv.Columns[index].ValueType = tipo; dtgv.Columns[index].Name = nombre; dtgv.Columns[index].HeaderText = textoCabecera; dtgv.Columns[index].Width = ancho; dtgv.Columns[index].ReadOnly = soloLectura; dtgv.Columns[index].Visible = visible; dtgv.Columns[index].DefaultCellStyle.Alignment = alignment; dtgv.Columns[index].DefaultCellStyle.Format = formato; dtgv.Columns[index].AutoSizeMode = autoSizeColumnMode; dtgv.Columns[index].SortMode = DataGridViewColumnSortMode.NotSortable; }
private T CreateColumnGeneric <T>(string mappingName, string headerName, DataGridViewAutoSizeColumnMode autoSizeMode, int?width) where T : DataGridViewColumn, new() { T ret = new T(); ret.Name = mappingName; ret.DataPropertyName = mappingName; ret.HeaderText = headerName; ret.AutoSizeMode = autoSizeMode; if (width != null) { ret.Width = width.Value; } return(ret); }
public SimpleDataGridViewColumn( DataGridViewAutoSizeColumnMode? autoSizeColumnMode, DataGridViewColumnHeaderCell headerCell, DataGridViewColumnSortMode? sortMode, Type defaultHeaderCellType, Type valueType, string dataPropertyName, string headerText, string name, int? dividerWidth, int? displayIndex, float? fillWeight, int? minWidth, int? width, DataGridViewCellStyle defaultCellStyle, bool resizable, bool? frozen, bool? readOnly, bool? visible) { InitializeNonVirtualProperties( autoSizeColumnMode, headerCell, sortMode, defaultHeaderCellType, valueType, dataPropertyName, headerText, name, dividerWidth, displayIndex, fillWeight, minWidth, width); InitializeVirtualProperties(defaultCellStyle, resizable, frozen, readOnly, visible); }
public virtual int GetPreferredWidth(DataGridViewAutoSizeColumnMode autoSizeColumnMode, bool fixedHeight) { switch (autoSizeColumnMode) { case DataGridViewAutoSizeColumnMode.NotSet: case DataGridViewAutoSizeColumnMode.None: case DataGridViewAutoSizeColumnMode.Fill: throw new ArgumentException("AutoSizeColumnMode is invalid"); } if (fixedHeight) { return(MinimumWidth); } else { return(MinimumWidth); } }
// Token: 0x0600048D RID: 1165 RVA: 0x001D9424 File Offset: 0x001D7824 public void method_11(string string_0, L1.GEnum0 genum0_0, DataGridViewAutoSizeColumnMode dataGridViewAutoSizeColumnMode_0) { Collection collection = this.collection_0; Collection obj = collection; lock (obj) { DataGridViewColumn dataGridViewColumn = null; switch (genum0_0) { case L1.GEnum0.Text: dataGridViewColumn = new DataGridViewTextBoxColumn(); break; case L1.GEnum0.Link: dataGridViewColumn = new DataGridViewLinkColumn(); break; case L1.GEnum0.Image: { DataGridViewImageColumn dataGridViewImageColumn = new DataGridViewImageColumn { ImageLayout = DataGridViewImageCellLayout.Zoom }; dataGridViewColumn = dataGridViewImageColumn; break; } case L1.GEnum0.StretchImage: { DataGridViewImageColumn dataGridViewImageColumn = new DataGridViewImageColumn { ImageLayout = DataGridViewImageCellLayout.Stretch }; dataGridViewColumn = dataGridViewImageColumn; break; } } dataGridViewColumn.AutoSizeMode = dataGridViewAutoSizeColumnMode_0; dataGridViewColumn.Tag = genum0_0; dataGridViewColumn.HeaderText = string_0; this.Columns.Add(dataGridViewColumn); } }
private static bool?IsAutoSizingToContent(DataGridViewAutoSizeColumnMode autoSizeMode) { switch (autoSizeMode) { case DataGridViewAutoSizeColumnMode.NotSet: return(null); case DataGridViewAutoSizeColumnMode.None: case DataGridViewAutoSizeColumnMode.Fill: case DataGridViewAutoSizeColumnMode.ColumnHeader: return(false); case DataGridViewAutoSizeColumnMode.AllCells: case DataGridViewAutoSizeColumnMode.AllCellsExceptHeader: case DataGridViewAutoSizeColumnMode.DisplayedCells: case DataGridViewAutoSizeColumnMode.DisplayedCellsExceptHeader: return(true); default: throw new ArgumentOutOfRangeException(nameof(autoSizeMode), autoSizeMode, null); } }
public void InitializeNonVirtualProperties( DataGridViewAutoSizeColumnMode? autoSizeColumnMode, DataGridViewColumnHeaderCell headerCell, DataGridViewColumnSortMode? sortMode, Type defaultHeaderCellType, Type valueType, string dataPropertyName, string headerText, string name, int? dividerWidth, int? displayIndex, float? fillWeight, int? minWidth, int? width) { this.AutoSizeMode = autoSizeColumnMode ?? DataGridViewAutoSizeColumnMode.AllCells; this.DataPropertyName = dataPropertyName ?? "Text"; this.DividerWidth = dividerWidth ?? 2; this.DisplayIndex = displayIndex ?? _defaultDisplayIndex++; this.FillWeight = fillWeight ?? 10; this.HeaderCell = headerCell ?? new DataGridViewColumnHeaderCell(); this.HeaderText = headerText; this.MinimumWidth = minWidth ?? 50; this.Width = width ?? 100; this.Name = name; this.SortMode = sortMode ?? DataGridViewColumnSortMode.Programmatic; this.DefaultHeaderCellType = defaultHeaderCellType ?? Type.GetType("string"); this.ValueType = valueType ?? Type.GetType("string"); }
/// <include file='doc\DataGridViewAutoSizeColumnsModeEventArgs.uex' path='docs/doc[@for="DataGridViewAutoSizeColumnsModeEventArgs.DataGridViewAutoSizeColumnsModeEventArgs"]/*' /> public DataGridViewAutoSizeColumnsModeEventArgs(DataGridViewAutoSizeColumnMode[] previousModes) { this.previousModes = previousModes; }
public DGVColumn(string cname, string dname, DataGridViewAutoSizeColumnMode mode) { ColName = cname; DataPropertyName = dname; AutoSizeMode = mode; }
public virtual int GetPreferredWidth(DataGridViewAutoSizeColumnMode autoSizeColumnMode, bool fixedHeight) { if (((autoSizeColumnMode == DataGridViewAutoSizeColumnMode.NotSet) || (autoSizeColumnMode == DataGridViewAutoSizeColumnMode.None)) || (autoSizeColumnMode == DataGridViewAutoSizeColumnMode.Fill)) { throw new ArgumentException(System.Windows.Forms.SR.GetString("DataGridView_NeedColumnAutoSizingCriteria", new object[] { "autoSizeColumnMode" })); } switch (autoSizeColumnMode) { case DataGridViewAutoSizeColumnMode.NotSet: case DataGridViewAutoSizeColumnMode.None: case DataGridViewAutoSizeColumnMode.ColumnHeader: case DataGridViewAutoSizeColumnMode.AllCellsExceptHeader: case DataGridViewAutoSizeColumnMode.AllCells: case DataGridViewAutoSizeColumnMode.DisplayedCellsExceptHeader: case DataGridViewAutoSizeColumnMode.DisplayedCells: case DataGridViewAutoSizeColumnMode.Fill: { int preferredWidth; int num3; DataGridViewRow row; DataGridView dataGridView = base.DataGridView; if (dataGridView == null) { return -1; } DataGridViewAutoSizeColumnCriteriaInternal internal2 = (DataGridViewAutoSizeColumnCriteriaInternal) autoSizeColumnMode; int num = 0; if (dataGridView.ColumnHeadersVisible && ((internal2 & DataGridViewAutoSizeColumnCriteriaInternal.Header) != DataGridViewAutoSizeColumnCriteriaInternal.NotSet)) { if (fixedHeight) { preferredWidth = this.HeaderCell.GetPreferredWidth(-1, dataGridView.ColumnHeadersHeight); } else { preferredWidth = this.HeaderCell.GetPreferredSize(-1).Width; } if (num < preferredWidth) { num = preferredWidth; } } if ((internal2 & DataGridViewAutoSizeColumnCriteriaInternal.AllRows) != DataGridViewAutoSizeColumnCriteriaInternal.NotSet) { for (num3 = dataGridView.Rows.GetFirstRow(DataGridViewElementStates.Visible); num3 != -1; num3 = dataGridView.Rows.GetNextRow(num3, DataGridViewElementStates.Visible)) { row = dataGridView.Rows.SharedRow(num3); if (fixedHeight) { preferredWidth = row.Cells[base.Index].GetPreferredWidth(num3, row.Thickness); } else { preferredWidth = row.Cells[base.Index].GetPreferredSize(num3).Width; } if (num < preferredWidth) { num = preferredWidth; } } return num; } if ((internal2 & DataGridViewAutoSizeColumnCriteriaInternal.DisplayedRows) != DataGridViewAutoSizeColumnCriteriaInternal.NotSet) { int height = dataGridView.LayoutInfo.Data.Height; int num5 = 0; for (num3 = dataGridView.Rows.GetFirstRow(DataGridViewElementStates.Visible | DataGridViewElementStates.Frozen); (num3 != -1) && (num5 < height); num3 = dataGridView.Rows.GetNextRow(num3, DataGridViewElementStates.Visible | DataGridViewElementStates.Frozen)) { row = dataGridView.Rows.SharedRow(num3); if (fixedHeight) { preferredWidth = row.Cells[base.Index].GetPreferredWidth(num3, row.Thickness); } else { preferredWidth = row.Cells[base.Index].GetPreferredSize(num3).Width; } if (num < preferredWidth) { num = preferredWidth; } num5 += row.Thickness; } if (num5 >= height) { return num; } for (num3 = dataGridView.DisplayedBandsInfo.FirstDisplayedScrollingRow; (num3 != -1) && (num5 < height); num3 = dataGridView.Rows.GetNextRow(num3, DataGridViewElementStates.Visible)) { row = dataGridView.Rows.SharedRow(num3); if (fixedHeight) { preferredWidth = row.Cells[base.Index].GetPreferredWidth(num3, row.Thickness); } else { preferredWidth = row.Cells[base.Index].GetPreferredSize(num3).Width; } if (num < preferredWidth) { num = preferredWidth; } num5 += row.Thickness; } } return num; } } throw new InvalidEnumArgumentException("value", (int) autoSizeColumnMode, typeof(DataGridViewAutoSizeColumnMode)); }
// Constructors public DataGridViewAutoSizeColumnModeEventArgs(DataGridViewColumn dataGridViewColumn, DataGridViewAutoSizeColumnMode previousMode) {}
public void AutoResizeColumn(int columnIndex, DataGridViewAutoSizeColumnMode autoSizeColumnMode) { this.AutoResizeColumn(columnIndex, autoSizeColumnMode, true); }
internal void OnAutoSizeColumnModeChanged(DataGridViewColumn dataGridViewColumn, DataGridViewAutoSizeColumnMode previousInheritedMode) { DataGridViewAutoSizeColumnModeEventArgs e = new DataGridViewAutoSizeColumnModeEventArgs(dataGridViewColumn, previousInheritedMode); this.OnAutoSizeColumnModeChanged(e); }
internal void AutoResizeColumnInternal (int columnIndex, DataGridViewAutoSizeColumnMode mode) { // http://msdn2.microsoft.com/en-us/library/ms171605.aspx int size = 0; DataGridViewColumn col = Columns [columnIndex]; switch (mode) { case DataGridViewAutoSizeColumnMode.Fill: return; case DataGridViewAutoSizeColumnMode.AllCellsExceptHeader: case DataGridViewAutoSizeColumnMode.AllCells: case DataGridViewAutoSizeColumnMode.DisplayedCells: case DataGridViewAutoSizeColumnMode.DisplayedCellsExceptHeader: size = Math.Max (CalculateColumnCellWidth (columnIndex, col.InheritedAutoSizeMode), col.HeaderCell.ContentBounds.Width); break; case DataGridViewAutoSizeColumnMode.ColumnHeader: size = col.HeaderCell.ContentBounds.Width; break; default: size = col.Width; break; } if (size < 0) size = 0; if (size < col.MinimumWidth) size = col.MinimumWidth; col.Width = size; }
public virtual int GetPreferredWidth(DataGridViewAutoSizeColumnMode autoSizeColumnMode, bool fixedHeight) {}
unsafe void setDgvWidth(DataGridView dgv, int* cc, int l, DataGridViewAutoSizeColumnMode a)/*กำหนดรูปแบบของ datagirdview*/ { for (int i = 0; i < l; i++) { dgv.Columns[cc->ToInt()].AutoSizeMode = a; cc++; } }
public void AutoResizeColumn (int columnIndex, DataGridViewAutoSizeColumnMode autoSizeColumnMode) { AutoResizeColumnInternal (columnIndex, autoSizeColumnMode); }
public void SetColumnVisible(string ColumnName, string DisplayName, int Width, int ColumnPosition, DataGridViewAutoSizeColumnMode AutoSizeColumnMode) { DataGridViewColumn _column = new DataGridViewColumn(); _column.CellTemplate = new DataGridViewTextBoxCell(); _column.Name = ColumnName; _column.HeaderText = DisplayName; _column.DataPropertyName = ColumnName; _column.Width = Width; _column.DisplayIndex = ColumnPosition; _column.AutoSizeMode = AutoSizeColumnMode; _column.SortMode = DataGridViewColumnSortMode.Automatic; this.Columns.Add(_column); this._ColumnsVisible.Add(ColumnName); }
public DataGridViewAutoSizeColumnModeEventArgs(DataGridViewColumn dataGridViewColumn, DataGridViewAutoSizeColumnMode previousMode) { this.dataGridViewColumn = dataGridViewColumn; this.previousMode = previousMode; }
public void SetColumnVisible(string ColumnName, string DisplayName, int Width, int ColumnPosition, ColumnStyle Style, DataGridViewAutoSizeColumnMode AutoSizeColumnMode) { DataGridViewColumn _column = new DataGridViewColumn(); _column.CellTemplate = new DataGridViewTextBoxCell(); _column.Name = ColumnName; _column.HeaderText = DisplayName; _column.DataPropertyName = ColumnName; _column.Width = Width; _column.DisplayIndex = ColumnPosition; _column.AutoSizeMode = AutoSizeColumnMode; _column.SortMode = DataGridViewColumnSortMode.Automatic; switch (Style) { case ColumnStyle.CheckBoxColumn: _column.CellTemplate = new DataGridViewCheckBoxCell(true); break; case ColumnStyle.ImageColumn: _column.CellTemplate = new DataGridViewImageCell(); break; case ColumnStyle.ComboBoxColumn: _column.CellTemplate = new DataGridViewComboBoxCell(); break; case ColumnStyle.LinkColumn: _column.CellTemplate = new DataGridViewLinkCell(); break; case ColumnStyle.ButtonColumn: _column.CellTemplate = new DataGridViewButtonCell(); break; } this.Columns.Add(_column); this._ColumnsVisible.Add(ColumnName); }
/// <include file='doc\DataGridView.uex' path='docs/doc[@for="DataGridView.AutoResizeColumn2"]/*' /> protected void AutoResizeColumn(int columnIndex, DataGridViewAutoSizeColumnMode autoSizeColumnMode, bool fixedHeight) { if (autoSizeColumnMode == DataGridViewAutoSizeColumnMode.NotSet || autoSizeColumnMode == DataGridViewAutoSizeColumnMode.None || autoSizeColumnMode == DataGridViewAutoSizeColumnMode.Fill) { throw new ArgumentException(SR.GetString(SR.DataGridView_NeedColumnAutoSizingCriteria, "autoSizeColumnMode")); } switch (autoSizeColumnMode) { case DataGridViewAutoSizeColumnMode.NotSet: case DataGridViewAutoSizeColumnMode.None: case DataGridViewAutoSizeColumnMode.ColumnHeader: case DataGridViewAutoSizeColumnMode.AllCellsExceptHeader: case DataGridViewAutoSizeColumnMode.AllCells: case DataGridViewAutoSizeColumnMode.DisplayedCellsExceptHeader: case DataGridViewAutoSizeColumnMode.DisplayedCells: case DataGridViewAutoSizeColumnMode.Fill: break; default: throw new InvalidEnumArgumentException("autoSizeColumnMode", (int)autoSizeColumnMode, typeof(DataGridViewAutoSizeColumnMode)); } if (columnIndex < 0 || columnIndex >= this.Columns.Count) { throw new ArgumentOutOfRangeException("columnIndex"); } if (autoSizeColumnMode == DataGridViewAutoSizeColumnMode.ColumnHeader && !this.ColumnHeadersVisible) { throw new InvalidOperationException(SR.GetString(SR.DataGridView_CannotAutoSizeInvisibleColumnHeader)); } AutoResizeColumnInternal(columnIndex, (DataGridViewAutoSizeColumnCriteriaInternal) autoSizeColumnMode, fixedHeight); }
internal void OnAutoSizeColumnModeChanged(DataGridViewColumn dataGridViewColumn, DataGridViewAutoSizeColumnMode previousInheritedMode) { Debug.Assert(dataGridViewColumn != null); DataGridViewAutoSizeColumnModeEventArgs dgvascme = new DataGridViewAutoSizeColumnModeEventArgs(dataGridViewColumn, previousInheritedMode); OnAutoSizeColumnModeChanged(dgvascme); }
protected void AutoResizeColumn (int columnIndex, DataGridViewAutoSizeColumnMode autoSizeColumnMode, bool fixedHeight) { AutoResizeColumn (columnIndex, autoSizeColumnMode); }
public virtual int GetPreferredWidth (DataGridViewAutoSizeColumnMode autoSizeColumnMode, bool fixedHeight) { switch (autoSizeColumnMode) { case DataGridViewAutoSizeColumnMode.NotSet: case DataGridViewAutoSizeColumnMode.None: case DataGridViewAutoSizeColumnMode.Fill: throw new ArgumentException("AutoSizeColumnMode is invalid"); } if (fixedHeight) { return 0; } else { return 0; } }
internal int CalculateColumnCellWidth (int index, DataGridViewAutoSizeColumnMode mode) { int first_row = 0; int last_row = Rows.Count; int result = 0; if (mode == DataGridViewAutoSizeColumnMode.DisplayedCells || mode == DataGridViewAutoSizeColumnMode.DisplayedCellsExceptHeader) { first_row = first_row_index; last_row = DisplayedRowCount (true);; } for (int i = first_row; i < last_row; i++) { if (!Rows[i].Visible) continue; int cell_width = Rows[i].Cells[index].PreferredSize.Width; result = Math.Max (result, cell_width); } return result; }
public void AutoResizeColumn(int columnIndex, DataGridViewAutoSizeColumnMode autoSizeColumnMode) {}
protected void AutoResizeColumn(int columnIndex, DataGridViewAutoSizeColumnMode autoSizeColumnMode, bool fixedHeight) { if (((autoSizeColumnMode == DataGridViewAutoSizeColumnMode.NotSet) || (autoSizeColumnMode == DataGridViewAutoSizeColumnMode.None)) || (autoSizeColumnMode == DataGridViewAutoSizeColumnMode.Fill)) { throw new ArgumentException(System.Windows.Forms.SR.GetString("DataGridView_NeedColumnAutoSizingCriteria", new object[] { "autoSizeColumnMode" })); } switch (autoSizeColumnMode) { case DataGridViewAutoSizeColumnMode.NotSet: case DataGridViewAutoSizeColumnMode.None: case DataGridViewAutoSizeColumnMode.ColumnHeader: case DataGridViewAutoSizeColumnMode.AllCellsExceptHeader: case DataGridViewAutoSizeColumnMode.AllCells: case DataGridViewAutoSizeColumnMode.DisplayedCellsExceptHeader: case DataGridViewAutoSizeColumnMode.DisplayedCells: case DataGridViewAutoSizeColumnMode.Fill: if ((columnIndex < 0) || (columnIndex >= this.Columns.Count)) { throw new ArgumentOutOfRangeException("columnIndex"); } if ((autoSizeColumnMode == DataGridViewAutoSizeColumnMode.ColumnHeader) && !this.ColumnHeadersVisible) { throw new InvalidOperationException(System.Windows.Forms.SR.GetString("DataGridView_CannotAutoSizeInvisibleColumnHeader")); } this.AutoResizeColumnInternal(columnIndex, (DataGridViewAutoSizeColumnCriteriaInternal) autoSizeColumnMode, fixedHeight); return; } throw new InvalidEnumArgumentException("autoSizeColumnMode", (int) autoSizeColumnMode, typeof(DataGridViewAutoSizeColumnMode)); }
/// <include file='doc\DataGridViewAutoSizeColumnModeEventArgs.uex' path='docs/doc[@for="DataGridViewAutoSizeColumnModeEventArgs.DataGridViewAutoSizeColumnModeEventArgs"]/*' /> public DataGridViewAutoSizeColumnModeEventArgs(DataGridViewColumn dataGridViewColumn, DataGridViewAutoSizeColumnMode previousMode) { Debug.Assert(dataGridViewColumn != null); this.dataGridViewColumn = dataGridViewColumn; this.previousMode = previousMode; }
/// <include file='doc\DataGridViewColumn.uex' path='docs/doc[@for="DataGridViewColumn.GetPreferredWidth"]/*' /> public virtual int GetPreferredWidth(DataGridViewAutoSizeColumnMode autoSizeColumnMode, bool fixedHeight) { if (autoSizeColumnMode == DataGridViewAutoSizeColumnMode.NotSet || autoSizeColumnMode == DataGridViewAutoSizeColumnMode.None || autoSizeColumnMode == DataGridViewAutoSizeColumnMode.Fill) { throw new ArgumentException(SR.GetString(SR.DataGridView_NeedColumnAutoSizingCriteria, "autoSizeColumnMode")); } switch (autoSizeColumnMode) { case DataGridViewAutoSizeColumnMode.NotSet: case DataGridViewAutoSizeColumnMode.None: case DataGridViewAutoSizeColumnMode.ColumnHeader: case DataGridViewAutoSizeColumnMode.AllCellsExceptHeader: case DataGridViewAutoSizeColumnMode.AllCells: case DataGridViewAutoSizeColumnMode.DisplayedCellsExceptHeader: case DataGridViewAutoSizeColumnMode.DisplayedCells: case DataGridViewAutoSizeColumnMode.Fill: break; default: throw new InvalidEnumArgumentException("value", (int) autoSizeColumnMode, typeof(DataGridViewAutoSizeColumnMode)); } DataGridView dataGridView = this.DataGridView; Debug.Assert(dataGridView == null || this.Index > -1); if (dataGridView == null) { return -1; } DataGridViewAutoSizeColumnCriteriaInternal autoSizeColumnCriteriaInternal = (DataGridViewAutoSizeColumnCriteriaInternal) autoSizeColumnMode; Debug.Assert(autoSizeColumnCriteriaInternal == DataGridViewAutoSizeColumnCriteriaInternal.Header || autoSizeColumnCriteriaInternal == DataGridViewAutoSizeColumnCriteriaInternal.AllRows || autoSizeColumnCriteriaInternal == DataGridViewAutoSizeColumnCriteriaInternal.DisplayedRows || autoSizeColumnCriteriaInternal == (DataGridViewAutoSizeColumnCriteriaInternal.Header | DataGridViewAutoSizeColumnCriteriaInternal.AllRows) || autoSizeColumnCriteriaInternal == (DataGridViewAutoSizeColumnCriteriaInternal.Header | DataGridViewAutoSizeColumnCriteriaInternal.DisplayedRows)); int preferredColumnThickness = 0, preferredCellThickness, rowIndex; DataGridViewRow dataGridViewRow; Debug.Assert(dataGridView.ColumnHeadersVisible || autoSizeColumnCriteriaInternal != DataGridViewAutoSizeColumnCriteriaInternal.Header); // take into account the preferred width of the header cell if displayed and cared about if (dataGridView.ColumnHeadersVisible && (autoSizeColumnCriteriaInternal & DataGridViewAutoSizeColumnCriteriaInternal.Header) != 0) { if (fixedHeight) { preferredCellThickness = this.HeaderCell.GetPreferredWidth(-1, dataGridView.ColumnHeadersHeight); } else { preferredCellThickness = this.HeaderCell.GetPreferredSize(-1).Width; } if (preferredColumnThickness < preferredCellThickness) { preferredColumnThickness = preferredCellThickness; } } if ((autoSizeColumnCriteriaInternal & DataGridViewAutoSizeColumnCriteriaInternal.AllRows) != 0) { for (rowIndex = dataGridView.Rows.GetFirstRow(DataGridViewElementStates.Visible); rowIndex != -1; rowIndex = dataGridView.Rows.GetNextRow(rowIndex, DataGridViewElementStates.Visible)) { dataGridViewRow = dataGridView.Rows.SharedRow(rowIndex); if (fixedHeight) { preferredCellThickness = dataGridViewRow.Cells[this.Index].GetPreferredWidth(rowIndex, dataGridViewRow.Thickness); } else { preferredCellThickness = dataGridViewRow.Cells[this.Index].GetPreferredSize(rowIndex).Width; } if (preferredColumnThickness < preferredCellThickness) { preferredColumnThickness = preferredCellThickness; } } } else if ((autoSizeColumnCriteriaInternal & DataGridViewAutoSizeColumnCriteriaInternal.DisplayedRows) != 0) { int displayHeight = dataGridView.LayoutInfo.Data.Height; int cy = 0; rowIndex = dataGridView.Rows.GetFirstRow(DataGridViewElementStates.Visible | DataGridViewElementStates.Frozen); while (rowIndex != -1 && cy < displayHeight) { dataGridViewRow = dataGridView.Rows.SharedRow(rowIndex); if (fixedHeight) { preferredCellThickness = dataGridViewRow.Cells[this.Index].GetPreferredWidth(rowIndex, dataGridViewRow.Thickness); } else { preferredCellThickness = dataGridViewRow.Cells[this.Index].GetPreferredSize(rowIndex).Width; } if (preferredColumnThickness < preferredCellThickness) { preferredColumnThickness = preferredCellThickness; } cy += dataGridViewRow.Thickness; rowIndex = dataGridView.Rows.GetNextRow(rowIndex, DataGridViewElementStates.Visible | DataGridViewElementStates.Frozen); } if (cy < displayHeight) { rowIndex = dataGridView.DisplayedBandsInfo.FirstDisplayedScrollingRow; while (rowIndex != -1 && cy < displayHeight) { dataGridViewRow = dataGridView.Rows.SharedRow(rowIndex); if (fixedHeight) { preferredCellThickness = dataGridViewRow.Cells[this.Index].GetPreferredWidth(rowIndex, dataGridViewRow.Thickness); } else { preferredCellThickness = dataGridViewRow.Cells[this.Index].GetPreferredSize(rowIndex).Width; } if (preferredColumnThickness < preferredCellThickness) { preferredColumnThickness = preferredCellThickness; } cy += dataGridViewRow.Thickness; rowIndex = dataGridView.Rows.GetNextRow(rowIndex, DataGridViewElementStates.Visible); } } } return preferredColumnThickness; }
unsafe void setDgvWidth(DataGridView dgv, int* cc, int l, DataGridViewAutoSizeColumnMode a) { for (int i = 0; i < l; i++) { dgv.Columns[cc->ToInt()].AutoSizeMode = a; cc++; } }