Skip to content

Commit ebdbaf1

Browse files
author
Ricardo Bossan (BEYONDSOFT CONSULTING INC) (from Dev Box)
committed
Add checks for CellPainting
1 parent 77ec5c9 commit ebdbaf1

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

src/System.Windows.Forms/src/System/Windows/Forms/Controls/DataGridView/DataGridViewCell.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3671,7 +3671,9 @@ internal void PaintWork(Graphics graphics,
36713671
cellStyle,
36723672
advancedBorderStyle,
36733673
paintParts);
3674-
dataGridView.OnCellPainting(dgvcpe);
3674+
3675+
dataGridView?.OnCellPainting(dgvcpe);
3676+
36753677
if (dgvcpe.Handled)
36763678
{
36773679
return;

src/System.Windows.Forms/src/System/Windows/Forms/Controls/DataGridView/DataGridViewCheckBoxCell.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -839,9 +839,9 @@ protected override void OnKeyUp(KeyEventArgs e, int rowIndex)
839839
e.Handled = true;
840840
}
841841

842-
NotifyMSAAClient(ColumnIndex, rowIndex);
842+
NotifyMSAAClient(ColumnIndex, rowIndex);
843+
}
843844
}
844-
}
845845

846846
protected override void OnLeave(int rowIndex, bool throughMouseClick)
847847
{
@@ -967,9 +967,12 @@ private void NotifyUiaClient()
967967

968968
private void NotifyMSAAClient(int columnIndex, int rowIndex)
969969
{
970-
Debug.Assert(DataGridView is not null);
971-
Debug.Assert((columnIndex >= 0) && (columnIndex < DataGridView.Columns.Count));
972-
Debug.Assert((rowIndex >= 0) && (rowIndex < DataGridView.Rows.Count));
970+
if (DataGridView is null ||
971+
columnIndex < 0 || columnIndex >= DataGridView.Columns.Count ||
972+
rowIndex < 0 || rowIndex >= DataGridView.Rows.Count)
973+
{
974+
return;
975+
}
973976

974977
int visibleRowIndex = DataGridView.Rows.GetRowCount(DataGridViewElementStates.Visible, 0, rowIndex);
975978
int visibleColumnIndex = DataGridView.Columns.ColumnIndexToActualDisplayIndex(columnIndex, DataGridViewElementStates.Visible);
@@ -1043,7 +1046,11 @@ private Rectangle PaintPrivate(
10431046
bool computeErrorIconBounds,
10441047
bool paint)
10451048
{
1049+
if(DataGridView is null)
10461050
// Parameter checking.
1051+
{
1052+
return Rectangle.Empty;
1053+
}
10471054

10481055
// One bit and one bit only should be turned on
10491056
Debug.Assert(paint || computeContentBounds || computeErrorIconBounds);

src/System.Windows.Forms/src/System/Windows/Forms/Controls/DataGridView/DataGridViewRow.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,9 +786,13 @@ private void BuildInheritedRowHeaderCellStyle(DataGridViewCellStyle inheritedCel
786786

787787
private void BuildInheritedRowStyle(int rowIndex, DataGridViewCellStyle inheritedRowStyle)
788788
{
789+
if (DataGridView is null)
790+
{
791+
return;
792+
}
793+
789794
Debug.Assert(inheritedRowStyle is not null);
790795
Debug.Assert(rowIndex >= 0);
791-
Debug.Assert(DataGridView is not null);
792796

793797
DataGridViewCellStyle? rowStyle = null;
794798
if (HasDefaultCellStyle)

src/System.Windows.Forms/src/System/Windows/Forms/Controls/DataGridView/DataGridViewRowHeaderCell.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,12 @@ private Rectangle PaintPrivate(
653653
bool cellSelected = (dataGridViewElementState & DataGridViewElementStates.Selected) != 0;
654654

655655
Debug.Assert(DataGridView is not null);
656+
657+
if (DataGridView is null)
658+
{
659+
return Rectangle.Empty;
660+
}
661+
656662
if (DataGridView.ApplyVisualStylesToHeaderCells)
657663
{
658664
if (cellStyle.Padding != Padding.Empty)

src/System.Windows.Forms/src/System/Windows/Forms/Controls/DataGridView/DataGridViewTextBoxCell.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,11 @@ private Rectangle PaintPrivate(
649649
bool computeErrorIconBounds,
650650
bool paint)
651651
{
652+
if (DataGridView is null)
653+
{
654+
return Rectangle.Empty;
655+
}
656+
652657
// Parameter checking. One bit and one bit only should be turned on.
653658
Debug.Assert(paint || computeContentBounds || computeErrorIconBounds);
654659
Debug.Assert(!paint || !computeContentBounds || !computeErrorIconBounds);

0 commit comments

Comments
 (0)