Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes Exception being thrown when the space key is pressed on a CheckBoxCell #12821

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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 ||
Copy link
Member

@Tanya-Solyanik Tanya-Solyanik Jan 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change you don't need null-check on line 842

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 @@ -1004,6 +1007,11 @@ protected override void Paint(
{
ArgumentNullException.ThrowIfNull(cellStyle);

if (DataGridView is null)
{
return;
}

PaintPrivate(
graphics,
clipBounds,
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 @@ -652,7 +652,11 @@ 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 @@ -610,6 +610,11 @@ protected override void Paint(
{
ArgumentNullException.ThrowIfNull(cellStyle);

if (DataGridView is null)
{
return;
}

PaintPrivate(
graphics,
clipBounds,
Expand Down