Skip to content

Commit

Permalink
Add checks for CellPainting
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricardo Bossan (BEYONDSOFT CONSULTING INC) (from Dev Box) committed Jan 28, 2025
1 parent 77ec5c9 commit ebdbaf1
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3671,7 +3671,9 @@ internal void PaintWork(Graphics graphics,
cellStyle,
advancedBorderStyle,
paintParts);
dataGridView.OnCellPainting(dgvcpe);

dataGridView?.OnCellPainting(dgvcpe);

if (dgvcpe.Handled)
{
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -839,9 +839,9 @@ protected override void OnKeyUp(KeyEventArgs e, int rowIndex)
e.Handled = true;
}

NotifyMSAAClient(ColumnIndex, rowIndex);
NotifyMSAAClient(ColumnIndex, rowIndex);
}
}
}

protected override void OnLeave(int rowIndex, bool throughMouseClick)
{
Expand Down Expand Up @@ -967,9 +967,12 @@ private void NotifyUiaClient()

private void NotifyMSAAClient(int columnIndex, int rowIndex)
{
Debug.Assert(DataGridView is not null);
Debug.Assert((columnIndex >= 0) && (columnIndex < DataGridView.Columns.Count));
Debug.Assert((rowIndex >= 0) && (rowIndex < DataGridView.Rows.Count));
if (DataGridView is null ||
columnIndex < 0 || columnIndex >= DataGridView.Columns.Count ||
rowIndex < 0 || rowIndex >= DataGridView.Rows.Count)
{
return;
}

int visibleRowIndex = DataGridView.Rows.GetRowCount(DataGridViewElementStates.Visible, 0, rowIndex);
int visibleColumnIndex = DataGridView.Columns.ColumnIndexToActualDisplayIndex(columnIndex, DataGridViewElementStates.Visible);
Expand Down Expand Up @@ -1043,7 +1046,11 @@ private Rectangle PaintPrivate(
bool computeErrorIconBounds,
bool paint)
{
if(DataGridView is null)
// Parameter checking.
{
return Rectangle.Empty;
}

// One bit and one bit only should be turned on
Debug.Assert(paint || computeContentBounds || computeErrorIconBounds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -786,9 +786,13 @@ private void BuildInheritedRowHeaderCellStyle(DataGridViewCellStyle inheritedCel

private void BuildInheritedRowStyle(int rowIndex, DataGridViewCellStyle inheritedRowStyle)
{
if (DataGridView is null)
{
return;
}

Debug.Assert(inheritedRowStyle is not null);
Debug.Assert(rowIndex >= 0);
Debug.Assert(DataGridView is not null);

DataGridViewCellStyle? rowStyle = null;
if (HasDefaultCellStyle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,12 @@ private Rectangle PaintPrivate(
bool cellSelected = (dataGridViewElementState & DataGridViewElementStates.Selected) != 0;

Debug.Assert(DataGridView is not null);

if (DataGridView is null)
{
return Rectangle.Empty;
}

if (DataGridView.ApplyVisualStylesToHeaderCells)
{
if (cellStyle.Padding != Padding.Empty)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,11 @@ private Rectangle PaintPrivate(
bool computeErrorIconBounds,
bool paint)
{
if (DataGridView is null)
{
return Rectangle.Empty;
}

// Parameter checking. One bit and one bit only should be turned on.
Debug.Assert(paint || computeContentBounds || computeErrorIconBounds);
Debug.Assert(!paint || !computeContentBounds || !computeErrorIconBounds);
Expand Down

0 comments on commit ebdbaf1

Please sign in to comment.