DataGridViewRowContextMenuStripNeededEventHandler デリゲートとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > DataGridViewRowContextMenuStripNeededEventHandler デリゲートの意味・解説 

DataGridViewRowContextMenuStripNeededEventHandler デリゲート

メモ : このデリゲートは、.NET Framework version 2.0新しく追加されたものです。

DataGridView の RowContextMenuStripNeeded イベント処理するメソッド表します

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

Public Delegate Sub DataGridViewRowContextMenuStripNeededEventHandler
 ( _
    sender As Object, _
    e As DataGridViewRowContextMenuStripNeededEventArgs _
)
Dim instance As New DataGridViewRowContextMenuStripNeededEventHandler(AddressOf
 HandlerMethod)
public delegate void DataGridViewRowContextMenuStripNeededEventHandler
 (
    Object sender,
    DataGridViewRowContextMenuStripNeededEventArgs e
)
public delegate void DataGridViewRowContextMenuStripNeededEventHandler
 (
    Object^ sender, 
    DataGridViewRowContextMenuStripNeededEventArgs^ e
)
/** @delegate */
public delegate void DataGridViewRowContextMenuStripNeededEventHandler
 (
    Object sender, 
    DataGridViewRowContextMenuStripNeededEventArgs e
)
JScript では、デリゲート使用できますが、新規に宣言することはできません。

パラメータ

sender

イベントソース

e

イベント データ格納している DataGridViewRowContextMenuStripNeededEventArgs。

解説解説

RowContextMenuStripNeeded イベントは、DataGridView コントロールの DataSource プロパティ設定されているか、VirtualMode プロパティtrue である場合にのみ発生しますRowContextMenuStripNeeded イベント処理すると、行の現在の状態や行含まれる値によって決定されるショートカット メニュー表示する場合に便利です。

RowContextMenuStripNeeded イベント処理すると、ユーザーが行右クリックするたびに、ハンドラ指定したショートカット メニュー表示されます。ただし、クリックされた特定のセルショートカット メニューが、CellContextMenuStripNeeded によってオーバーライドされている場合除きます

RowContextMenuStripNeeded イベントは、プログラム上で、またはユーザーが行右クリックしたときに、DataGridViewRow.ContextMenuStrip プロパティの値が取得されたときにも発生します

DataGridViewRowContextMenuStripNeededEventArgs.RowIndex プロパティ使用すると、行の状態や行含まれる値を特定し、その情報使用して DataGridViewRowContextMenuStripNeededEventArgs.ContextMenuStrip プロパティ変更できます。このプロパティは、行の ContextMenuStrip プロパティの値によって初期化され、イベントの値によってオーバーライドされます

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

イベント処理詳細については、「イベント利用」を参照してください

DataGridViewRowContextMenuStripNeededEventHandler デリゲート作成する場合は、イベント処理するメソッド識別してくださいイベントイベント ハンドラ関連付けるには、デリゲートインスタンスイベント追加しますデリゲート削除しない限り、そのイベント発生すると常にイベント ハンドラ呼び出されます。イベント ハンドラ デリゲート詳細については、「イベントデリゲート」を参照してください

使用例使用例

次のコード例では、RowContextMenuStripNeeded イベント処理することにより、従業員役職応じた ContextMenuStrip を表示する方法示してます。この例では、2 種類コンテキスト メニューがあり、1 つ経営者向け、もう 1 つはその他すべての従業員向けです。

Public Sub dataGridView1_RowContextMenuStripNeeded(
 _
    ByVal sender As Object,
 _
    ByVal e As DataGridViewRowContextMenuStripNeededEventArgs)
 _
    Handles dataGridView1.RowContextMenuStripNeeded

    Dim dataGridViewRow1 As DataGridViewRow
 = _
    dataGridView1.Rows(e.RowIndex)

    toolStripMenuItem1.Enabled = True

    ' Show the appropriate ContextMenuStrip based on the employees title.
    If dataGridViewRow1.Cells("Title").Value.ToString()
 = _
        "Sales Manager" OrElse
 _
        dataGridViewRow1.Cells("Title").Value.ToString()
 = _
        "Vice President, Sales" Then

        e.ContextMenuStrip = managerMenuStrip
    Else
        e.ContextMenuStrip = employeeMenuStrip
    End If

    contextMenuRowIndex = e.RowIndex
End Sub
void dataGridView1_RowContextMenuStripNeeded(object sender,
    DataGridViewRowContextMenuStripNeededEventArgs e)
{
    DataGridViewRow dataGridViewRow1 = dataGridView1.Rows[e.RowIndex];

    toolStripMenuItem1.Enabled = true;

    // Show the appropriate ContextMenuStrip based on the employees
 title.
    if ((dataGridViewRow1.Cells["Title"].Value.ToString()
 ==
        "Sales Manager") ||
        (dataGridViewRow1.Cells["Title"].Value.ToString() ==
        "Vice President, Sales"))
    {
        e.ContextMenuStrip = managerMenuStrip;
    }
    else
    {
        e.ContextMenuStrip = employeeMenuStrip;
    }

    contextMenuRowIndex = e.RowIndex;
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
System.Windows.Forms 名前空間
ContextMenuStrip クラス
DataGridView クラス
DataGridView.RowContextMenuStripNeeded イベント
DataGridView.DataSource プロパティ
DataGridView.VirtualMode プロパティ
DataGridViewRowContextMenuStripNeededEventArgs クラス
DataGridViewRowContextMenuStripNeededEventArgs.ContextMenuStrip プロパティ
DataGridViewRow.ContextMenuStrip プロパティ
その他の技術情報
Windows フォーム DataGridView コントロール拡張するための推奨される手順



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

辞書ショートカット

すべての辞書の索引

DataGridViewRowContextMenuStripNeededEventHandler デリゲートのお隣キーワード
検索ランキング

   

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



DataGridViewRowContextMenuStripNeededEventHandler デリゲートのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS