DataGridView.CurrentCellAddress Propriedade

Definição

Obtém os índices das linhas e colunas da célula atualmente ativa.

public:
 property System::Drawing::Point CurrentCellAddress { System::Drawing::Point get(); };
[System.ComponentModel.Browsable(false)]
public System.Drawing.Point CurrentCellAddress { get; }
[<System.ComponentModel.Browsable(false)>]
member this.CurrentCellAddress : System.Drawing.Point
Public ReadOnly Property CurrentCellAddress As Point

Valor de Propriedade

A Point que representa os índices de linha e coluna da célula atualmente ativa.

Atributos

Exemplos

O exemplo de código seguinte ilustra como usar a CurrentCellAddress propriedade num cenário de pintura de linhas. No exemplo, esta propriedade é usada para armazenar o índice de linhas da célula atual. Quando o utilizador altera a célula atual para uma fila diferente, a fila é forçada 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 esta propriedade para determinar a linha e a coluna da célula atual sem aceder diretamente à célula. Isto é útil para evitar deixar de partilhar linhas partilhadas. Para obter mais informações sobre a partilha de linhas, consulte Práticas Recomendadas para Dimensionar o Controle DataGridView do Windows Forms.

Aplica-se a

Ver também