public static DataGridViewAdvancedBorderStyle AdjustCellBorderStyle <TCell>(TCell cell) where TCell : DataGridViewCell, ISpannedCell { var dataGridViewAdvancedBorderStylePlaceholder = new DataGridViewAdvancedBorderStyle(); var dataGridView = cell.DataGridView; return(cell.AdjustCellBorderStyle( dataGridView.AdvancedCellBorderStyle, dataGridViewAdvancedBorderStylePlaceholder, DataGridViewHelper.SingleVerticalBorderAdded(dataGridView), DataGridViewHelper.SingleHorizontalBorderAdded(dataGridView), InFirstDisplayedColumn(cell), InFirstDisplayedRow(cell))); }
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { if (m_OwnerCell != null && m_OwnerCell.DataGridView == null) { m_OwnerCell = null; //owner cell was removed. } if (DataGridView == null || (m_OwnerCell == null && m_ColumnSpan == 1 && m_RowSpan == 1)) { base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); return; } var ownerCell = this; var columnIndex = ColumnIndex; var columnSpan = m_ColumnSpan; var rowSpan = m_RowSpan; if (m_OwnerCell != null) { ownerCell = m_OwnerCell; columnIndex = m_OwnerCell.ColumnIndex; rowIndex = m_OwnerCell.RowIndex; columnSpan = m_OwnerCell.ColumnSpan; rowSpan = m_OwnerCell.RowSpan; value = m_OwnerCell.GetValue(rowIndex); errorText = m_OwnerCell.GetErrorText(rowIndex); cellState = m_OwnerCell.State; cellStyle = m_OwnerCell.GetInheritedStyle(null, rowIndex, true); formattedValue = m_OwnerCell.GetFormattedValue(value, rowIndex, ref cellStyle, null, null, DataGridViewDataErrorContexts.Display); } if (CellsRegionContainsSelectedCell(columnIndex, rowIndex, columnSpan, rowSpan)) { cellState |= DataGridViewElementStates.Selected; } var cellBounds2 = DataGridViewCellExHelper.GetSpannedCellBoundsFromChildCellBounds( this, cellBounds, DataGridViewHelper.SingleVerticalBorderAdded(DataGridView), DataGridViewHelper.SingleHorizontalBorderAdded(DataGridView)); clipBounds = DataGridViewCellExHelper.GetSpannedCellClipBounds(ownerCell, cellBounds2, DataGridViewHelper.SingleVerticalBorderAdded(DataGridView), DataGridViewHelper.SingleHorizontalBorderAdded(DataGridView)); using (var g = DataGridView.CreateGraphics()) { g.SetClip(clipBounds); //Paint the content. advancedBorderStyle = DataGridViewCellExHelper.AdjustCellBorderStyle(ownerCell); ownerCell.NativePaint(g, clipBounds, cellBounds2, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts & ~DataGridViewPaintParts.Border); //Paint the borders. if ((paintParts & DataGridViewPaintParts.Border) != DataGridViewPaintParts.None) { var leftTopCell = ownerCell; var advancedBorderStyle2 = new DataGridViewAdvancedBorderStyle { Left = advancedBorderStyle.Left, Top = advancedBorderStyle.Top, Right = DataGridViewAdvancedCellBorderStyle.None, Bottom = DataGridViewAdvancedCellBorderStyle.None }; leftTopCell.PaintBorder(g, clipBounds, cellBounds2, cellStyle, advancedBorderStyle2); var rightBottomCell = DataGridView[columnIndex + columnSpan - 1, rowIndex + rowSpan - 1] as DataGridViewTextBoxCellEx ?? this; var advancedBorderStyle3 = new DataGridViewAdvancedBorderStyle { Left = DataGridViewAdvancedCellBorderStyle.None, Top = DataGridViewAdvancedCellBorderStyle.None, Right = advancedBorderStyle.Right, Bottom = advancedBorderStyle.Bottom }; rightBottomCell.PaintBorder(g, clipBounds, cellBounds2, cellStyle, advancedBorderStyle3); } } }