/// <summary> /// Adjusts the column width relative to the given <see cref="MultiHeaderCell"/> based on its width. /// </summary> /// <param name="headerCell">A <see cref="MultiHeaderCell"/> object.</param> private void AdjustColumnsWidth(MultiHeaderCell headerCell) { if (headerCell == null || !AutoSizeColumnsBasedOnAdditionalHeadersContent || AutoSizeColumnsMode == DataGridViewAutoSizeColumnsMode.None) { return; } // Calculate the total width of the base columns the headerCell spans var spanningInfo = MultiHeaderCellsSpanningInfo.GetHeaderCellSpanningInfo(this, headerCell); // Nothing to do if the spanning columns width already accomodates space for the computed headerCell's width if (spanningInfo.TotalSpanningWidth >= headerCell.CellSize.Width) { return; } // Re-adjust grid's columns widths spanned by the headerCell int remainder; int proportionalWidthToIncrease = Math.DivRem(headerCell.CellSize.Width - spanningInfo.VisibleWidth, headerCell.ColumnSpan, out remainder); if (remainder > 0) { proportionalWidthToIncrease++; } int lastColumnIndex = headerCell.GetLastBaseColumnIndexFromSpan(Columns.Count); for (int idx = headerCell.ColumnIndex; idx <= lastColumnIndex; idx++) { DataGridViewColumn spanningColumn = Columns[idx]; int newWidth = spanningColumn.Width + proportionalWidthToIncrease; _skipColumnWidthsAdjustment = true; spanningColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; spanningColumn.Width = newWidth; _skipColumnWidthsAdjustment = false; } }
/// <summary> /// Initializes a new instance of the <see cref="HeaderCellTextChangedArgs"/> class. /// </summary> /// <param name="headerCell">The <see cref="MultiHeaderCell"/> object whose column span changed.</param> /// <param name="oldText">The old value of the <see cref="MultiHeaderCell.Text"/> property.</param> public HeaderCellTextChangedArgs(MultiHeaderCell headerCell, string oldText) { HeaderCell = headerCell; OldText = oldText; }
/// <summary> /// Initializes a new instance of the <see cref="HeaderCellColumnSpanChangedArgs"/> class. /// </summary> /// <param name="headerCell">The <see cref="MultiHeaderCell"/> object whose column span changed.</param> /// <param name="oldColumnSpan">The old value of the <see cref="MultiHeaderCell.ColumnSpan"/> property.</param> public HeaderCellColumnSpanChangedArgs(MultiHeaderCell headerCell, int oldColumnSpan) { HeaderCell = headerCell; OldColumnSpan = oldColumnSpan; }