DataGridViewRowPrePaintEventArgs::DrawFocus Method (Rectangle, Boolean)
Draws the focus rectangle around the specified bounds.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Parameters
- bounds
-
Type:
System.Drawing::Rectangle
A Rectangle that specifies the focus area.
- cellsPaintSelectionBackground
-
Type:
System::Boolean
true to use the SelectionBackColor property of the DataGridViewRow::InheritedStyle property to determine the color of the focus rectangle; false to use the BackColor property of the DataGridViewRow::InheritedStyle.
| Exception | Condition |
|---|---|
| InvalidOperationException | RowIndex is less than zero or greater than the number of rows in the DataGridView control minus one. |
Use the DrawFocus method when you draw the DataGridViewRow and its cells' contents yourself. If you manually paint the entire row and its cells' contents, set the HandledEventArgs::Handled property to true. When HandledEventArgs::Handled is true, the CellPainting and RowPostPaint events do not occur.
The following code example demonstrates how to use the DrawFocus method to draw a focus around the visible cells of the row. The code actually uses the DataGridViewRowPostPaintEventArgs::DrawFocus method, which is nearly identical to the DrawFocus method of DataGridViewRowPrePaintEventArgs. This example is part of a larger example available in How to: Customize the Appearance of Rows in the Windows Forms DataGridView Control.
Available since 2.0