更新 : 2007 年 11 月
現在アクティブなセルの行インデックスおよび列インデックスを取得します。
名前空間 :
System.Windows.Forms アセンブリ :
System.Windows.Forms (System.Windows.Forms.dll 内)
<BrowsableAttribute(False)> _
Public ReadOnly Property CurrentCellAddress As Point
Dim instance As DataGridView
Dim value As Point
value = instance.CurrentCellAddress
[BrowsableAttribute(false)]
public Point CurrentCellAddress { get; }
[BrowsableAttribute(false)]
public:
property Point CurrentCellAddress {
Point get ();
}
/** @property */
/** @attribute BrowsableAttribute(false) */
public Point get_CurrentCellAddress()
public function get CurrentCellAddress () : Point
セルに直接アクセスせずに現在のセルの行および列を確認するには、このプロパティを使用します。これは、共有行が非共有にならないようにする場合に便利です。行の共有の詳細については、「Windows フォーム DataGridView コントロールを拡張するための推奨される手順」を参照してください。
行を描画するシナリオで CurrentCellAddress プロパティを使用する方法のコード例を次に示します。この例では、このプロパティは現在のセルの行インデックスを格納するために使用されます。ユーザーが現在のセルを別の行に変更すると、行は強制的に再描画されます。
ここに示すコードは、「方法 : Windows フォームの DataGridView コントロールの行の外観をカスタマイズする」で取り上げられているコードの一部です。
' 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
// 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
参照
その他の技術情報