public virtual int GetPreferredHeight(int rowIndex, DataGridViewAutoSizeRowMode autoSizeRowMode, bool fixedWidth)
        {
            DataGridViewRow row;

            if (DataGridView != null)
            {
                row = DataGridView.Rows.SharedRow(rowIndex);
            }
            else
            {
                row = this;
            }

            int height = 0;

            if (autoSizeRowMode == DataGridViewAutoSizeRowMode.AllCells || autoSizeRowMode == DataGridViewAutoSizeRowMode.RowHeader)
            {
                height = Math.Max(height, row.HeaderCell.PreferredSize.Height);
            }

            if (autoSizeRowMode == DataGridViewAutoSizeRowMode.AllCells || autoSizeRowMode == DataGridViewAutoSizeRowMode.AllCellsExceptHeader)
            {
                foreach (DataGridViewCell cell in row.Cells)
                {
                    height = Math.Max(height, cell.PreferredSize.Height);
                }
            }

            return(height);
        }
Example #2
0
		public override int GetPreferredHeight(int rowIndex, DataGridViewAutoSizeRowMode autoSizeRowMode, bool fixedWidth)
		{
			int h =  base.GetPreferredHeight(rowIndex, autoSizeRowMode, fixedWidth);
			return h;
		}
        /// <include file='doc\DataGridView.uex' path='docs/doc[@for="DataGridView.AutoResizeRows3"]/*' />
        protected void AutoResizeRows(int rowIndexStart, int rowsCount, DataGridViewAutoSizeRowMode autoSizeRowMode, bool fixedWidth)
        {
            // not using ClientUtils.IsEnumValid here because DataGridViewAutoSizeRowCriteriaInternal is a flags enum.
            if (((DataGridViewAutoSizeRowCriteriaInternal) autoSizeRowMode & invalidDataGridViewAutoSizeRowCriteriaInternalMask) != 0)
            {
                throw new InvalidEnumArgumentException("autoSizeRowMode", (int) autoSizeRowMode, typeof(DataGridViewAutoSizeRowMode));
            }

            if (autoSizeRowMode == DataGridViewAutoSizeRowMode.RowHeader && !this.RowHeadersVisible)
            {
                throw new InvalidOperationException(SR.GetString(SR.DataGridView_CannotAutoSizeRowsInvisibleRowHeader));
            }

            if (rowsCount < 0)
            {
                throw new ArgumentOutOfRangeException("rowsCount");
            }

            if (rowIndexStart < 0)
            {
                throw new ArgumentOutOfRangeException("rowIndexStart");
            }

            if (!this.IsHandleCreated)
            {
                // auto sizing causes handle creation.
                // don't create the handle inside InitializeComponent because that causes problems w/ data binding
                this.dataGridViewState2[DATAGRIDVIEWSTATE2_autoSizedWithoutHandle] = true;
                return;
            }

            this.inBulkPaintCount++;
            this.inBulkLayoutCount++;
            try
            {
                int rowIndex = this.Rows.GetNextRow(rowIndexStart - 1, DataGridViewElementStates.Visible);
                int autoSizedCount = 0;
                while (rowIndex != -1 && autoSizedCount < rowsCount)
                {
                    AutoResizeRowInternal(rowIndex, autoSizeRowMode, fixedWidth, false /*internalAutosizing*/);
                    autoSizedCount++;
                    if (autoSizedCount < rowsCount)
                    {
                        rowIndex = this.Rows.GetNextRow(rowIndex, DataGridViewElementStates.Visible);
                    }
                }
            }
            finally
            {
                ExitBulkLayout(true /*invalidInAdjustFillingColumns*/);
                ExitBulkPaint(-1, -1);
            }
        }
        private void AutoResizeRowInternal(int rowIndex, DataGridViewAutoSizeRowMode autoSizeRowMode, bool fixedWidth, bool internalAutosizing)
        {
            Debug.Assert(rowIndex >= 0 && rowIndex < this.Rows.Count);
            Debug.Assert(((DataGridViewAutoSizeRowCriteriaInternal) autoSizeRowMode & invalidDataGridViewAutoSizeRowCriteriaInternalMask) == 0);

            if (!this.IsHandleCreated)
            {
                // auto sizing causes handle creation.
                // don't create the handle inside InitializeComponent because that causes problems w/ data binding
                this.dataGridViewState2[DATAGRIDVIEWSTATE2_autoSizedWithoutHandle] = true;
                return;
            }

            try
            {
                this.noAutoSizeCount++;
                // Use of WindowsFormsUtils.CreateMeasurementGraphics() avoid use of this.Handle
                // IntPtr handle = this.Handle; // Force creation of control's handle because for databound grids, handle creation wipes out and recreates the columns/rows.
                // Note: Even none-resizable row can programmatically be resized.
                DataGridViewRow dataGridViewRow = this.Rows.SharedRow(rowIndex);
                int height, minimumHeight;
                dataGridViewRow.GetHeightInfo(rowIndex, out height, out minimumHeight);
                int preferredThickness = dataGridViewRow.GetPreferredHeight(rowIndex, autoSizeRowMode, fixedWidth);
                if (preferredThickness < minimumHeight)
                {
                    preferredThickness = minimumHeight;
                }
                if (preferredThickness > DataGridViewBand.maxBandThickness)
                {
                    preferredThickness = DataGridViewBand.maxBandThickness;
                }
                if (height != preferredThickness)
                {
                    if (this.autoSizeRowsMode == DataGridViewAutoSizeRowsMode.None)
                    {
                        if (!OnRowHeightInfoPushed(rowIndex, preferredThickness, minimumHeight))
                        {
                            this.Rows[rowIndex].ThicknessInternal = preferredThickness;   // unsharing the resized row
                        }
                    }
                    else
                    {
                        if (internalAutosizing)
                        {
                            this.Rows[rowIndex].ThicknessInternal = preferredThickness;   // unsharing the resized row
                        }
                        else
                        {
                            this.Rows[rowIndex].Thickness = preferredThickness;   // unsharing the resized row
                        }
                    }
                }
            }
            finally
            {
                Debug.Assert(this.noAutoSizeCount > 0);
                this.noAutoSizeCount--;
            }
        }
 /// <include file='doc\DataGridView.uex' path='docs/doc[@for="DataGridView.AutoResizeRow2"]/*' />
 protected void AutoResizeRow(int rowIndex, DataGridViewAutoSizeRowMode autoSizeRowMode, bool fixedWidth)
 {
     if (rowIndex < 0 || rowIndex >= this.Rows.Count)
     {
         throw new ArgumentOutOfRangeException("rowIndex");
     }
     // not using ClientUtils here because it's a flags enum, masking instead.
     if (((DataGridViewAutoSizeRowCriteriaInternal) autoSizeRowMode & invalidDataGridViewAutoSizeRowCriteriaInternalMask) != 0)
     {
         throw new InvalidEnumArgumentException("autoSizeRowMode", (int) autoSizeRowMode, typeof(DataGridViewAutoSizeRowMode));
     }
     if (autoSizeRowMode == DataGridViewAutoSizeRowMode.RowHeader && !this.RowHeadersVisible)
     {
         throw new InvalidOperationException(SR.GetString(SR.DataGridView_CannotAutoSizeRowInvisibleRowHeader));
     }
     AutoResizeRowInternal(rowIndex, autoSizeRowMode, fixedWidth, false /*internalAutosizing*/);
 }
		public virtual int GetPreferredHeight (int rowIndex, DataGridViewAutoSizeRowMode autoSizeRowMode, bool fixedWidth)
		{
			DataGridViewRow row;
			
			if (DataGridView != null)
				row = DataGridView.Rows.SharedRow (rowIndex);
			else
				row = this;

			int height = 0;

			if (autoSizeRowMode == DataGridViewAutoSizeRowMode.AllCells || autoSizeRowMode == DataGridViewAutoSizeRowMode.RowHeader)
				height = Math.Max (height, row.HeaderCell.PreferredSize.Height);

			if (autoSizeRowMode == DataGridViewAutoSizeRowMode.AllCells || autoSizeRowMode == DataGridViewAutoSizeRowMode.AllCellsExceptHeader)
				foreach (DataGridViewCell cell in row.Cells)
					height = Math.Max (height, cell.PreferredSize.Height);
			
			return height;
		}
 protected void AutoResizeRow(int rowIndex, DataGridViewAutoSizeRowMode autoSizeRowMode, bool fixedWidth)
 {
     if ((rowIndex < 0) || (rowIndex >= this.Rows.Count))
     {
         throw new ArgumentOutOfRangeException("rowIndex");
     }
     if ((autoSizeRowMode & ~DataGridViewAutoSizeRowMode.AllCells) != ((DataGridViewAutoSizeRowMode) 0))
     {
         throw new InvalidEnumArgumentException("autoSizeRowMode", (int) autoSizeRowMode, typeof(DataGridViewAutoSizeRowMode));
     }
     if ((autoSizeRowMode == DataGridViewAutoSizeRowMode.RowHeader) && !this.RowHeadersVisible)
     {
         throw new InvalidOperationException(System.Windows.Forms.SR.GetString("DataGridView_CannotAutoSizeRowInvisibleRowHeader"));
     }
     this.AutoResizeRowInternal(rowIndex, autoSizeRowMode, fixedWidth, false);
 }
Example #8
0
		protected void AutoResizeRow (int rowIndex, DataGridViewAutoSizeRowMode autoSizeRowMode, bool fixedWidth)
		{
			if (autoSizeRowMode == DataGridViewAutoSizeRowMode.RowHeader && !rowHeadersVisible)
				throw new InvalidOperationException ("row headers are not visible");
			if (rowIndex < 0 || rowIndex > Rows.Count - 1)
				throw new ArgumentOutOfRangeException ("rowIndex");

			DataGridViewRow row = GetRowInternal (rowIndex);

			int new_height = row.GetPreferredHeight (rowIndex, autoSizeRowMode, true);

			if (row.Height != new_height)
				row.SetAutoSizeHeight (new_height);
		}
 protected void AutoResizeRow(int rowIndex, DataGridViewAutoSizeRowMode autoSizeRowMode, bool fixedWidth);
Example #10
0
 public void AutoResizeRow(int rowIndex, DataGridViewAutoSizeRowMode autoSizeRowMode)
 {
 }
Example #11
0
 public virtual int GetPreferredHeight(int rowIndex, DataGridViewAutoSizeRowMode autoSizeRowMode, bool fixedWidth)
 {
     throw null;
 }
	public virtual int GetPreferredHeight(int rowIndex, DataGridViewAutoSizeRowMode autoSizeRowMode, bool fixedWidth) {}
Example #13
0
        public override int GetPreferredHeight(int rowIndex, DataGridViewAutoSizeRowMode autoSizeRowMode, bool fixedWidth)
        {
            int h = base.GetPreferredHeight(rowIndex, autoSizeRowMode, fixedWidth);

            return(h);
        }
 protected void AutoResizeRows(int rowIndexStart, int rowsCount, DataGridViewAutoSizeRowMode autoSizeRowMode, bool fixedWidth)
 {
     if ((autoSizeRowMode & ~DataGridViewAutoSizeRowMode.AllCells) != ((DataGridViewAutoSizeRowMode) 0))
     {
         throw new InvalidEnumArgumentException("autoSizeRowMode", (int) autoSizeRowMode, typeof(DataGridViewAutoSizeRowMode));
     }
     if ((autoSizeRowMode == DataGridViewAutoSizeRowMode.RowHeader) && !this.RowHeadersVisible)
     {
         throw new InvalidOperationException(System.Windows.Forms.SR.GetString("DataGridView_CannotAutoSizeRowsInvisibleRowHeader"));
     }
     if (rowsCount < 0)
     {
         throw new ArgumentOutOfRangeException("rowsCount");
     }
     if (rowIndexStart < 0)
     {
         throw new ArgumentOutOfRangeException("rowIndexStart");
     }
     if (!base.IsHandleCreated)
     {
         this.dataGridViewState2[0x100000] = true;
     }
     else
     {
         this.inBulkPaintCount++;
         this.inBulkLayoutCount++;
         try
         {
             int nextRow = this.Rows.GetNextRow(rowIndexStart - 1, DataGridViewElementStates.Visible);
             int num2 = 0;
             while ((nextRow != -1) && (num2 < rowsCount))
             {
                 this.AutoResizeRowInternal(nextRow, autoSizeRowMode, fixedWidth, false);
                 num2++;
                 if (num2 < rowsCount)
                 {
                     nextRow = this.Rows.GetNextRow(nextRow, DataGridViewElementStates.Visible);
                 }
             }
         }
         finally
         {
             this.ExitBulkLayout(true);
             this.ExitBulkPaint(-1, -1);
         }
     }
 }
 private void AutoResizeRowInternal(int rowIndex, DataGridViewAutoSizeRowMode autoSizeRowMode, bool fixedWidth, bool internalAutosizing)
 {
     if (!base.IsHandleCreated)
     {
         this.dataGridViewState2[0x100000] = true;
     }
     else
     {
         try
         {
             int num;
             int num2;
             this.noAutoSizeCount++;
             DataGridViewRow row = this.Rows.SharedRow(rowIndex);
             row.GetHeightInfo(rowIndex, out num, out num2);
             int height = row.GetPreferredHeight(rowIndex, autoSizeRowMode, fixedWidth);
             if (height < num2)
             {
                 height = num2;
             }
             if (height > 0x10000)
             {
                 height = 0x10000;
             }
             if (num != height)
             {
                 if (this.autoSizeRowsMode == DataGridViewAutoSizeRowsMode.None)
                 {
                     if (!this.OnRowHeightInfoPushed(rowIndex, height, num2))
                     {
                         this.Rows[rowIndex].ThicknessInternal = height;
                     }
                 }
                 else if (internalAutosizing)
                 {
                     this.Rows[rowIndex].ThicknessInternal = height;
                 }
                 else
                 {
                     this.Rows[rowIndex].Thickness = height;
                 }
             }
         }
         finally
         {
             this.noAutoSizeCount--;
         }
     }
 }
 protected void AutoResizeRows(int rowIndexStart, int rowsCount, DataGridViewAutoSizeRowMode autoSizeRowMode,
                               bool fixedWidth);
Example #17
0
		public void AutoResizeRow (int rowIndex, DataGridViewAutoSizeRowMode autoSizeRowMode)
		{
			AutoResizeRow (rowIndex, autoSizeRowMode, true);
		}
 public virtual int GetPreferredHeight(int rowIndex, DataGridViewAutoSizeRowMode autoSizeRowMode, bool fixedWidth)
 {
     if ((autoSizeRowMode & ~DataGridViewAutoSizeRowMode.AllCells) != ((DataGridViewAutoSizeRowMode) 0))
     {
         throw new InvalidEnumArgumentException("autoSizeRowMode", (int) autoSizeRowMode, typeof(DataGridViewAutoSizeRowMode));
     }
     if ((base.DataGridView != null) && ((rowIndex < 0) || (rowIndex >= base.DataGridView.Rows.Count)))
     {
         throw new ArgumentOutOfRangeException("rowIndex");
     }
     if (base.DataGridView == null)
     {
         return -1;
     }
     int num = 0;
     if (base.DataGridView.RowHeadersVisible && ((autoSizeRowMode & DataGridViewAutoSizeRowMode.RowHeader) != ((DataGridViewAutoSizeRowMode) 0)))
     {
         if ((fixedWidth || (base.DataGridView.RowHeadersWidthSizeMode == DataGridViewRowHeadersWidthSizeMode.EnableResizing)) || (base.DataGridView.RowHeadersWidthSizeMode == DataGridViewRowHeadersWidthSizeMode.DisableResizing))
         {
             num = Math.Max(num, this.HeaderCell.GetPreferredHeight(rowIndex, base.DataGridView.RowHeadersWidth));
         }
         else
         {
             num = Math.Max(num, this.HeaderCell.GetPreferredSize(rowIndex).Height);
         }
     }
     if ((autoSizeRowMode & DataGridViewAutoSizeRowMode.AllCellsExceptHeader) != ((DataGridViewAutoSizeRowMode) 0))
     {
         foreach (DataGridViewCell cell in this.Cells)
         {
             DataGridViewColumn column = base.DataGridView.Columns[cell.ColumnIndex];
             if (column.Visible)
             {
                 int preferredHeight;
                 if (fixedWidth || ((column.InheritedAutoSizeMode & (DataGridViewAutoSizeColumnMode.DisplayedCellsExceptHeader | DataGridViewAutoSizeColumnMode.AllCellsExceptHeader)) == DataGridViewAutoSizeColumnMode.NotSet))
                 {
                     preferredHeight = cell.GetPreferredHeight(rowIndex, column.Width);
                 }
                 else
                 {
                     preferredHeight = cell.GetPreferredSize(rowIndex).Height;
                 }
                 if (num < preferredHeight)
                 {
                     num = preferredHeight;
                 }
             }
         }
     }
     return num;
 }
Example #19
0
		protected void AutoResizeRows (int rowIndexStart, int rowsCount, DataGridViewAutoSizeRowMode autoSizeRowMode, bool fixedWidth)
		{
			for (int i = rowIndexStart; i < rowIndexStart + rowsCount; i++)
				AutoResizeRow (i, autoSizeRowMode, fixedWidth);
		}
Example #20
0
        /// <include file='doc\DataGridViewRow.uex' path='docs/doc[@for="DataGridViewRow.GetPreferredHeight"]/*' />
        public virtual int GetPreferredHeight(int rowIndex, DataGridViewAutoSizeRowMode autoSizeRowMode, bool fixedWidth)
        {
            // not using IsEnumValid here because this is a flags enum, using mask instead.
            if (((DataGridViewAutoSizeRowCriteriaInternal) autoSizeRowMode & invalidDataGridViewAutoSizeRowCriteriaInternalMask) != 0)
            {
                throw new InvalidEnumArgumentException("autoSizeRowMode", (int) autoSizeRowMode, typeof(DataGridViewAutoSizeRowMode));
            }
            if (!(this.DataGridView == null || (rowIndex >= 0 && rowIndex < this.DataGridView.Rows.Count)))
            {
                throw new ArgumentOutOfRangeException("rowIndex");
            }
            if (this.DataGridView == null)
            {
                return -1;
            }

            int preferredRowThickness = 0, preferredCellThickness;
            // take into account the preferred height of the header cell if displayed and cared about
            if (this.DataGridView.RowHeadersVisible && 
                (((DataGridViewAutoSizeRowCriteriaInternal) autoSizeRowMode) & DataGridViewAutoSizeRowCriteriaInternal.Header) != 0)
            {
                if (fixedWidth ||
                    this.DataGridView.RowHeadersWidthSizeMode == DataGridViewRowHeadersWidthSizeMode.EnableResizing ||
                    this.DataGridView.RowHeadersWidthSizeMode == DataGridViewRowHeadersWidthSizeMode.DisableResizing)
                {
                    preferredRowThickness = Math.Max(preferredRowThickness, this.HeaderCell.GetPreferredHeight(rowIndex, this.DataGridView.RowHeadersWidth));
                }
                else
                {
                    preferredRowThickness = Math.Max(preferredRowThickness, this.HeaderCell.GetPreferredSize(rowIndex).Height);
                }
            }
            if ((((DataGridViewAutoSizeRowCriteriaInternal) autoSizeRowMode) & DataGridViewAutoSizeRowCriteriaInternal.AllColumns) != 0)
            {
                foreach (DataGridViewCell dataGridViewCell in this.Cells)
                {
                    DataGridViewColumn dataGridViewColumn = this.DataGridView.Columns[dataGridViewCell.ColumnIndex];
                    if (dataGridViewColumn.Visible)
                    {
                        if (fixedWidth ||
                            ((((DataGridViewAutoSizeColumnCriteriaInternal) dataGridViewColumn.InheritedAutoSizeMode) & (DataGridViewAutoSizeColumnCriteriaInternal.AllRows | DataGridViewAutoSizeColumnCriteriaInternal.DisplayedRows)) == 0))
                        {
                            preferredCellThickness = dataGridViewCell.GetPreferredHeight(rowIndex, dataGridViewColumn.Width);
                        }
                        else
                        {
                            preferredCellThickness = dataGridViewCell.GetPreferredSize(rowIndex).Height;
                        }
                        if (preferredRowThickness < preferredCellThickness)
                        {
                            preferredRowThickness = preferredCellThickness;
                        }
                    }
                }
            }
            return preferredRowThickness;
        }