DataGridView.CurrentCell プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > DataGridView.CurrentCell プロパティの意味・解説 

DataGridView.CurrentCell プロパティ

メモ : このプロパティは、.NET Framework version 2.0 で新しく追加されたものです。

現在アクティブなセルを取得または設定します。

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Dim instance As DataGridView
Dim value As DataGridViewCell

value = instance.CurrentCell

instance.CurrentCell = value
public DataGridViewCell CurrentCell { get;
 set; }
public:
property DataGridViewCell^ CurrentCell {
    DataGridViewCell^ get ();
    void set (DataGridViewCell^ value);
}
/** @property */
public DataGridViewCell get_CurrentCell ()

/** @property */
public void set_CurrentCell (DataGridViewCell
 value)
public function get CurrentCell
 () : DataGridViewCell

public function set CurrentCell
 (value : DataGridViewCell)

プロパティ値
現在のセルを表す DataGridViewCell。現在のセルがない場合は null 参照 (Visual Basic では Nothing)。既定では 1 列目の最初のセルになり、コントロールにセルが存在しない場合は null 参照 (Visual Basic では Nothing) になります。

例外例外
例外の種類条件

InvalidOperationException

現在のセルへの変更をコミットまたはキャンセルすることはできないため、このプロパティの値は設定できません。

または

このプロパティの設定時に指定されたセルは、非表示の行または列にあります。

ArgumentException

このプロパティの設定時に指定されたセルが DataGridView にありません。

解説解説

セルが現在のセルとして設定されていて、現在表示されていない場合は、スクロールして表示します。ヘッダー セルや無効なセル、非表示の行/列に存在するセルが現在のセルになることはできません。

このプロパティを null 参照 (Visual Basic では Nothing) に設定することにより、一時的にフォーカス四角形を削除できます。ただし、コントロールが再びフォーカスを受け取ったときに、このプロパティの値が null 参照 (Visual Basic では Nothing) であることがわかると、自動的に FirstDisplayedCell プロパティの値に設定されます。

このプロパティの値を変更すると、CurrentCellChanged イベントの前に、SelectionChanged イベントが発生します。このとき、CurrentCell プロパティにアクセスするすべての SelectionChanged イベント ハンドラには、変更前の値が渡されます。

DataGridView を外部データ ソースにバインドした場合、このプロパティはその既定値にリセットされます。

使用例使用例

現在のセルが並べ替えの後に表示されるようにするコード例を次に示します。このコードは、バインドされていない DataGridView コントロールでだけ使用できます。外部データ ソースにバインドされた DataGridView コントロールの場合、現在のセルは、並べ替え時に自動的に永続化されません。

この例を実行するには、dataGridView1 という名前の DataGridView が配置されているフォームに、次のコードを貼り付けます。C# では、Sorted イベントをイベント ハンドラに関連付ける必要もあります。

Private Sub dataGridView1_Sorted(ByVal
 sender As Object, _
    ByVal e As System.EventArgs) Handles
 dataGridView1.Sorted

    Me.dataGridView1.FirstDisplayedCell = Me.dataGridView1.CurrentCell

End Sub
private void dataGridView1_Sorted(object sender,
 EventArgs e)
{
    this.dataGridView1.FirstDisplayedCell = this.dataGridView1.CurrentCell;
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DataGridView クラス
DataGridView メンバ
System.Windows.Forms 名前空間
CurrentRow
SelectionChanged
CurrentCellChanged
FirstDisplayedCell
その他の技術情報
DataGridView コントロール (Windows フォーム)



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「DataGridView.CurrentCell プロパティ」の関連用語

DataGridView.CurrentCell プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DataGridView.CurrentCell プロパティのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS