DataGridView.CurrentCellAddress Egenskap

Definition

Hämtar rad- och kolumnindex för den aktiva cellen.

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

Egenskapsvärde

En Point som representerar rad- och kolumnindex för den aktiva cellen.

Attribut

Exempel

I följande kodexempel visas hur du använder egenskapen CurrentCellAddress i ett scenario med radmålning. I exemplet används den här egenskapen för att lagra radindexet för den aktuella cellen. När användaren ändrar den aktuella cellen till en annan rad tvingas raden att måla om sig själv.

Den här koden är en del av ett större exempel i Så här: Anpassa utseendet på rader i Windows Forms DataGridView Control.

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

Kommentarer

Använd den här egenskapen för att fastställa raden och kolumnen i den aktuella cellen utan att komma åt cellen direkt. Detta är användbart för att undvika att dela upp delade rader. Mer information om raddelning finns i Best Practices for Scaling the Windows Forms DataGridView Control.

Gäller för

Se även