DataGridViewCell.ContextMenuStrip 屬性

定義

取得或設定與儲存格相關聯的捷徑功能表。

public:
 virtual property System::Windows::Forms::ContextMenuStrip ^ ContextMenuStrip { System::Windows::Forms::ContextMenuStrip ^ get(); void set(System::Windows::Forms::ContextMenuStrip ^ value); };
public virtual System.Windows.Forms.ContextMenuStrip ContextMenuStrip { get; set; }
public virtual System.Windows.Forms.ContextMenuStrip? ContextMenuStrip { get; set; }
member this.ContextMenuStrip : System.Windows.Forms.ContextMenuStrip with get, set
Public Overridable Property ContextMenuStrip As ContextMenuStrip

屬性值

與儲存格相關聯的 ContextMenuStrip

備註

此屬性表示使用者以滑鼠右鍵單擊儲存格時通常會顯示的快捷方式選單。

DataGridView當控件DataSource屬性設定或其VirtualMode屬性為 true時,取得 屬性的值ContextMenuStrip會引發 CellContextMenuStripNeeded 控件的事件,並傳回 DataGridViewCellContextMenuStripNeededEventArgs.ContextMenuStrip 事件處理程式中指定的屬性值。 如果沒有事件的處理程式,取得 屬性的值 ContextMenuStrip 會傳回先前指定的值或預設值 null

CellContextMenuStripNeeded處理事件主要用於處理大量數據,以避免在設定多個單元格的數據格ContextMenuStrip值時降低效能。 如需詳細資訊,請參閱 縮放 Windows Form DataGridView 控制項的最佳做法

如果存在,變更這個屬性會 CellContextMenuStripChanged 引發擁有 DataGridView上的 事件。

您也可以藉由設定數據列屬性或處理DataGridView控件的事件RowContextMenuStripNeeded,來指定個別數據列ContextMenuStrip的快捷功能表,而不是個別的單元格。 單元格 ContextMenuStrip 屬性設定會覆寫數據列 ContextMenuStrip 屬性設定,而 CellContextMenuStripNeeded 事件則會同時覆寫 RowContextMenuStripNeeded 事件和數據列 ContextMenuStrip 屬性設定。 不過,您可以指定 null 儲存格快捷方式選單,以防止覆寫資料列快捷方式選單。

適用於

另請參閱