protected internal virtual void PaintCells(Graphics graphics, Rectangle clipBounds, Rectangle rowBounds, int rowIndex, DataGridViewElementStates rowState, bool isFirstDisplayedRow, bool isLastVisibleRow, DataGridViewPaintParts paintParts) { List <DataGridViewColumn> sortedColumns = DataGridView.Columns.ColumnDisplayIndexSortedArrayList; Rectangle bounds = rowBounds; // If row headers are visible, adjust our starting point if (DataGridView.RowHeadersVisible) { bounds.X += DataGridView.RowHeadersWidth; bounds.Width -= DataGridView.RowHeadersWidth; } bool singleVerticalBorderAdded = !DataGridView.RowHeadersVisible; bool singleHorizontalBorderAdded = !DataGridView.ColumnHeadersVisible; for (int i = DataGridView.first_col_index; i < sortedColumns.Count; i++) { DataGridViewColumn col = sortedColumns[i]; if (!col.Visible) { continue; } if (!col.Displayed) { break; } bounds.Width = col.Width; DataGridViewCell cell = Cells[col.Index]; if ((paintParts & DataGridViewPaintParts.Background) == DataGridViewPaintParts.Background) { graphics.FillRectangle(Brushes.White, bounds); } DataGridViewCellStyle style; if (cell.RowIndex == -1) { style = DefaultCellStyle; } else { style = cell.InheritedStyle; } object value; DataGridViewElementStates cellState; if (cell.RowIndex == -1) { // TODO: Look up value if databound. value = null; cellState = cell.State; } else { value = cell.Value; cellState = cell.InheritedState; } DataGridViewAdvancedBorderStyle intermediateBorderStyle = (DataGridViewAdvancedBorderStyle)((ICloneable)DataGridView.AdvancedCellBorderStyle).Clone(); DataGridViewAdvancedBorderStyle borderStyle = cell.AdjustCellBorderStyle(DataGridView.AdvancedCellBorderStyle, intermediateBorderStyle, singleVerticalBorderAdded, singleHorizontalBorderAdded, cell.ColumnIndex == 0, cell.RowIndex == 0); DataGridView.OnCellFormattingInternal(new DataGridViewCellFormattingEventArgs(cell.ColumnIndex, cell.RowIndex, value, cell.FormattedValueType, style)); cell.PaintWork(graphics, clipBounds, bounds, rowIndex, cellState, style, borderStyle, paintParts); bounds.X += bounds.Width; } }