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

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

DataGridViewRow.ContextMenuStrip プロパティ

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

行のショートカット メニュー取得または設定します

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

Public Overrides Property
 ContextMenuStrip As ContextMenuStrip
Dim instance As DataGridViewRow
Dim value As ContextMenuStrip

value = instance.ContextMenuStrip

instance.ContextMenuStrip = value
public override ContextMenuStrip ContextMenuStrip { get;
 set; }
public:
virtual property ContextMenuStrip^ ContextMenuStrip {
    ContextMenuStrip^ get () override;
    void set (ContextMenuStrip^ value) override;
}
/** @property */
public ContextMenuStrip get_ContextMenuStrip ()

/** @property */
public void set_ContextMenuStrip (ContextMenuStrip
 value)
public override function get
 ContextMenuStrip () : ContextMenuStrip

public override function set
 ContextMenuStrip (value : ContextMenuStrip)

プロパティ
現在の DataGridViewRow に関連付けられている ContextMenuStrip。既定値null 参照 (Visual Basic では Nothing) です。

例外例外
例外種類条件

InvalidOperationException

このプロパティの値の取得時に、行が DataGridView コントロール内にあり、共有行です。

解説解説

DataGridView コントロールの CellContextMenuStripNeeded イベントか行ContextMenuStrip プロパティが、クリックされた特定のセルショートカット メニューオーバーライドしていなければ、このプロパティは、ユーザーが行右クリックしたときに表示されるショートカット メニュー示します

DataGridView コントロールの DataSource プロパティ設定されている場合、または VirtualMode プロパティtrue場合ContextMenuStrip プロパティの値を取得すると、コントロールの RowContextMenuStripNeeded イベント発生しイベント ハンドラ指定された DataGridViewRowContextMenuStripNeededEventArgs.ContextMenuStrip プロパティの値が返されます。イベントハンドラない場合ContextMenuStrip プロパティの値を取得すると、以前指定された値、またはその既定値である null 参照 (Visual Basic では Nothing) が返されます。

RowContextMenuStripNeeded イベントの処理は、大量データを扱う場合に、複数行の ContextMenuStrip の値を設定する際のパフォーマンスの低下を防ぐために主に使用します詳細については、「Windows フォーム DataGridView コントロール拡張するための推奨される手順」を参照してください

このプロパティ変更すると、(もしあれば) 所有している側の DataGridView で RowContextMenuStripChanged イベント発生します

現在の行が共有されている場合は、このプロパティの値を取得するではなく、GetContextMenuStrip メソッド使用してください

使用例使用例

DataGridViewColumn.ContextMenuStrip プロパティ使用する方法次のコード例示します。このプロパティは、DataGridViewRow クラスContextMenuStrip プロパティとほぼ同じです。このコード例は、DataGridViewColumn クラストピック取り上げている、コード例一部分です。

WithEvents toolStripItem1 As New
 ToolStripMenuItem()

Private Sub AddContextMenu()
    toolStripItem1.Text = "Redden"
    Dim strip As New ContextMenuStrip()
    For Each column As DataGridViewColumn
 _
        In dataGridView.Columns()

        column.ContextMenuStrip = strip
        column.ContextMenuStrip.Items.Add(toolStripItem1)
    Next
End Sub
' Change the cell's color.
Private Sub toolStripItem1_Click(ByVal
 sender As Object, _
    ByVal args As EventArgs) _
    Handles toolStripItem1.Click

    dataGridView.Rows(mouseLocation.RowIndex) _
        .Cells(mouseLocation.ColumnIndex) _
        .Style.BackColor = Color.Red
End Sub

Private mouseLocation As DataGridViewCellEventArgs

' Deal with hovering over a cell.
Private Sub dataGridView_CellMouseEnter(ByVal
 sender As Object, _
    ByVal location As DataGridViewCellEventArgs)
 _
    Handles DataGridView.CellMouseEnter

    mouseLocation = location
End Sub
ToolStripMenuItem toolStripItem1 = new ToolStripMenuItem();

private void AddContextMenu()
{
    toolStripItem1.Text = "Redden";
    toolStripItem1.Click += new EventHandler(toolStripItem1_Click);
    ContextMenuStrip strip = new ContextMenuStrip();
    foreach (DataGridViewColumn column in dataGridView.Columns)
    {

        column.ContextMenuStrip = strip;
        column.ContextMenuStrip.Items.Add(toolStripItem1);
    }
}

private DataGridViewCellEventArgs mouseLocation;

// Change the cell's color.
private void toolStripItem1_Click(object sender,
 EventArgs args)
{
    dataGridView.Rows[mouseLocation.RowIndex]
        .Cells[mouseLocation.ColumnIndex].Style.BackColor
        = Color.Red;
}

// Deal with hovering over a cell.
private void dataGridView_CellMouseEnter(object
 sender,
    DataGridViewCellEventArgs location)
{
    mouseLocation = location;
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DataGridViewRow クラス
DataGridViewRow メンバ
System.Windows.Forms 名前空間
DataGridView クラス
DataGridView.RowContextMenuStripChanged イベント
DataGridView.RowContextMenuStripNeeded イベント
DataGridView.DataSource プロパティ
DataGridView.VirtualMode プロパティ
ContextMenuStrip クラス
その他の技術情報
Windows フォーム DataGridView コントロール拡張するための推奨される手順


このページでは「.NET Framework クラス ライブラリ リファレンス」からDataGridViewRow.ContextMenuStrip プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からDataGridViewRow.ContextMenuStrip プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からDataGridViewRow.ContextMenuStrip プロパティ を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「DataGridViewRow.ContextMenuStrip プロパティ」の関連用語

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

   

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



DataGridViewRow.ContextMenuStrip プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS