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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -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 ||
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 @@ -1043,7 +1046,11 @@ private Rectangle PaintPrivate(
bool computeErrorIconBounds,
bool paint)
{
if(DataGridView is null)
ricardobossan marked this conversation as resolved.
Show resolved Hide resolved
// 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);
ricardobossan marked this conversation as resolved.
Show resolved Hide resolved

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)
ricardobossan marked this conversation as resolved.
Show resolved Hide resolved
{
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