クリックして評価とフィードバックをお寄せください
MSDN
MSDN ライブラリ
.NET 開発
.NET Framework 3.5
.NET Framework
System.Windows.Forms 名前空間
DataGridView クラス
DataGridView プロパティ
 CurrentCellAddress プロパティ
このページは次のバージョンについて記述しています。
Microsoft Visual Studio 2008/.NET Framework 3.5

その他のバージョンについては、以下の情報を参照してください。
.NET Framework クラス ライブラリ
DataGridView..::.CurrentCellAddress プロパティ

更新 : 2007 年 11 月

現在アクティブなセルの行インデックスおよび列インデックスを取得します。

名前空間 :  System.Windows.Forms
アセンブリ :  System.Windows.Forms (System.Windows.Forms.dll 内)

Visual Basic (宣言)
<BrowsableAttribute(False)> _
Public ReadOnly Property CurrentCellAddress As Point
Visual Basic (使用法)
Dim instance As DataGridView
Dim value As Point

value = instance.CurrentCellAddress
C#
[BrowsableAttribute(false)]
public Point CurrentCellAddress { get; }
Visual C++
[BrowsableAttribute(false)]
public:
property Point CurrentCellAddress {
    Point get ();
}
J#
/** @property */
/** @attribute BrowsableAttribute(false) */
public Point get_CurrentCellAddress()
JScript
public function get CurrentCellAddress () : Point

プロパティ値

型 : System.Drawing..::.Point

現在アクティブなセルの行インデックスおよび列インデックスを表す Point

セルに直接アクセスせずに現在のセルの行および列を確認するには、このプロパティを使用します。これは、共有行が非共有にならないようにする場合に便利です。行の共有の詳細については、「Windows フォーム DataGridView コントロールを拡張するための推奨される手順」を参照してください。

行を描画するシナリオで CurrentCellAddress プロパティを使用する方法のコード例を次に示します。この例では、このプロパティは現在のセルの行インデックスを格納するために使用されます。ユーザーが現在のセルを別の行に変更すると、行は強制的に再描画されます。

ここに示すコードは、「方法 : Windows フォームの DataGridView コントロールの行の外観をカスタマイズする」で取り上げられているコードの一部です。

Visual Basic
' 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 'dataGridView1_CurrentCellChanged

C#
// 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;
}

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

.NET Framework および .NET Compact Framework では、各プラットフォームのすべてのバージョンはサポートしていません。サポートされているバージョンについては、「.NET Framework システム要件」を参照してください。

.NET Framework

サポート対象 : 3.5、3.0、2.0
コミュニティ コンテンツ   コミュニティ コンテンツとは
新しいコンテンツの追加 RSS  注釈
Processing
Page view tracker