DataGridViewRowPrePaintEventArgs.InheritedRowStyle プロパティ

定義

行に適用されるセル スタイルを取得します。

public:
 property System::Windows::Forms::DataGridViewCellStyle ^ InheritedRowStyle { System::Windows::Forms::DataGridViewCellStyle ^ get(); };
public System.Windows.Forms.DataGridViewCellStyle InheritedRowStyle { get; }
member this.InheritedRowStyle : System.Windows.Forms.DataGridViewCellStyle
Public ReadOnly Property InheritedRowStyle As DataGridViewCellStyle

プロパティ値

行に現在適用されているセル スタイルが格納された DataGridViewCellStyle

次のコード例では、 プロパティを使用して、 InheritedRowStyle 選択した行のカスタム背景を描画する方法を示します。 変数 eは 型 DataGridViewRowPrePaintEventArgsです。 このコード例は、「方法: Windows フォーム DataGridView コントロールの行の外観をカスタマイズする」で提供されるより大きな例の一部です。

// Determine whether the cell should be painted
// with the custom selection background.
if ((e.State & DataGridViewElementStates.Selected) ==
            DataGridViewElementStates.Selected)
{
    // Calculate the bounds of the row.
    Rectangle rowBounds = new Rectangle(
        this.dataGridView1.RowHeadersWidth, e.RowBounds.Top,
        this.dataGridView1.Columns.GetColumnsWidth(
            DataGridViewElementStates.Visible) -
        this.dataGridView1.HorizontalScrollingOffset + 1,
        e.RowBounds.Height);

    // Paint the custom selection background.
    using (Brush backbrush =
        new System.Drawing.Drawing2D.LinearGradientBrush(rowBounds,
            this.dataGridView1.DefaultCellStyle.SelectionBackColor,
            e.InheritedRowStyle.ForeColor,
            System.Drawing.Drawing2D.LinearGradientMode.Horizontal))
    {
        e.Graphics.FillRectangle(backbrush, rowBounds);
    }
}
' Determine whether the cell should be painted with the 
' custom selection background.
If (e.State And DataGridViewElementStates.Selected) = _
    DataGridViewElementStates.Selected Then

    ' Calculate the bounds of the row.
    Dim rowBounds As New Rectangle( _
        Me.dataGridView1.RowHeadersWidth, e.RowBounds.Top, _
        Me.dataGridView1.Columns.GetColumnsWidth( _
        DataGridViewElementStates.Visible) - _
        Me.dataGridView1.HorizontalScrollingOffset + 1, _
        e.RowBounds.Height)

    ' Paint the custom selection background.
    Dim backbrush As New _
        System.Drawing.Drawing2D.LinearGradientBrush(rowBounds, _
        Me.dataGridView1.DefaultCellStyle.SelectionBackColor, _
        e.InheritedRowStyle.ForeColor, _
        System.Drawing.Drawing2D.LinearGradientMode.Horizontal)
    Try
        e.Graphics.FillRectangle(backbrush, rowBounds)
    Finally
        backbrush.Dispose()
    End Try
End If

注釈

プロパティには InheritedRowStyle 、行の プロパティと同じ値が InheritedStyle 含まれています。 内の に DataGridViewRow 直接アクセスすると、パフォーマンスに影響する DataGridView 可能性があります。 行の共有解除をRowPrePaint回避し、最適なパフォーマンスを維持するには、 イベントで を使用InheritedRowStyleします。

InheritedRowStyle プロパティは読み取り専用です。 プロパティを使用して取得した のプロパティをDataGridViewCellStyleInheritedRowStyle設定できますが、新しい設定は無効になります。

適用対象

こちらもご覧ください