DataGridViewRowPrePaintEventArgs.InheritedRowStyle Proprietà

Definizione

Ottiene lo stile della cella applicato alla riga.

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

Valore della proprietà

Classe DataGridViewCellStyle contenente lo stile della cella applicato alla riga.

Esempio

Nell'esempio di codice seguente viene illustrato come utilizzare la InheritedRowStyle proprietà per disegnare uno sfondo personalizzato per la riga selezionata. La variabile, e, è di tipo DataGridViewRowPrePaintEventArgs. Questo esempio di codice fa parte di un esempio più ampio fornito in Procedura: Personalizzare l'aspetto delle righe nel controllo DataGridView Windows Forms.

// 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

Commenti

La InheritedRowStyle proprietà contiene gli stessi valori della proprietà della InheritedStyle riga. L'accesso DataGridView diretto a in DataGridViewRow può influire sulle prestazioni. Usare InheritedRowStyle nell'evento per evitare l'annullamento RowPrePaint delsharing della riga e mantenere prestazioni ottimali.

La proprietà InheritedRowStyle è di sola lettura. Sebbene sia possibile impostare le proprietà dell'oggetto DataGridViewCellStyle recuperato tramite la InheritedRowStyle proprietà , le nuove impostazioni non avranno alcun effetto.

Si applica a

Vedi anche