DataGridView.InvalidateRow(Int32) Método

Definição

Invalida a linha especificada do DataGridView, forçando a sua repintura.

public:
 void InvalidateRow(int rowIndex);
public void InvalidateRow(int rowIndex);
member this.InvalidateRow : int -> unit
Public Sub InvalidateRow (rowIndex As Integer)

Parâmetros

rowIndex
Int32

O índice da linha a invalidar.

Exceções

rowIndex não está no intervalo válido de 0 ao número de linhas menos 1.

Exemplos

O exemplo de código seguinte ilustra como usar o InvalidateRow método num cenário de pintura de linhas. No exemplo, a linha é invalidada quando a célula atual muda, forçando a fila a repintar-se.

Este código faz parte de um exemplo maior disponível em Como: Personalizar a Aparência das Linhas no Controlo Windows Forms DataGridView.

// Forces the row to repaint itself when the user changes the 
// current cell. This is necessary to refresh the focus rectangle.
void dataGridView1_CurrentCellChanged(object sender, EventArgs e)
{
    if (oldRowIndex != -1)
    {
        this.dataGridView1.InvalidateRow(oldRowIndex);
    }
    oldRowIndex = this.dataGridView1.CurrentCellAddress.Y;
}
' Forces the row to repaint itself when the user changes the 
' current cell. This is necessary to refresh the focus rectangle.
Sub dataGridView1_CurrentCellChanged(ByVal sender As Object, _
    ByVal e As EventArgs) Handles dataGridView1.CurrentCellChanged

    If oldRowIndex <> -1 Then
        Me.dataGridView1.InvalidateRow(oldRowIndex)
    End If
    oldRowIndex = Me.dataGridView1.CurrentCellAddress.Y

End Sub

Observações

Use este método para forçar uma carreira a repintar-se sozinha. Este método é útil em cenários de desenho do proprietário, onde lidas com os RowPrePaint eventos de ou.RowPostPaint

Para mais informações sobre pintura e invalidação, veja Invalidate.

Aplica-se a

Ver também