DataGridViewCell.ContextMenuStrip DataGridViewCell.ContextMenuStrip DataGridViewCell.ContextMenuStrip DataGridViewCell.ContextMenuStrip Property

定義

取得或設定與儲存格相關聯的捷徑功能表。Gets or sets the shortcut menu associated with the cell.

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; }
member this.ContextMenuStrip : System.Windows.Forms.ContextMenuStrip with get, set
Public Overridable Property ContextMenuStrip As ContextMenuStrip

屬性值

與儲存格相關聯的 ContextMenuStripThe ContextMenuStrip associated with the cell.

備註

這個屬性會指出當使用者以滑鼠右鍵按一下資料格時,通常會顯示的快捷方式功能表。This property indicates the shortcut menu that is typically displayed when the user right-clicks the cell.

VirtualMode true DataGridViewCellContextMenuStripNeededEventArgs.ContextMenuStrip CellContextMenuStripNeeded當控制項屬性DataSource已設定或其ContextMenuStrip屬性為時,取得屬性的值會引發控制項的事件,並傳回的值。 DataGridView在事件處理常式中指定的屬性。When the DataGridView control DataSource property is set or its VirtualMode property is true, getting the value of the ContextMenuStrip property raises the CellContextMenuStripNeeded event of the control and returns the value of the DataGridViewCellContextMenuStripNeededEventArgs.ContextMenuStrip property as specified in the event handler. 如果沒有事件的處理常式,取得ContextMenuStrip屬性的值會傳回先前指定的值或其預設null值。If there are no handlers for the event, getting the value of the ContextMenuStrip property returns the previously specified value or its default value of null.

在處理大量資料時,處理ContextMenuStrip 事件主要是很有用的,以避免在設定多個儲存格的儲存格值時發生效能上的負面影響。CellContextMenuStripNeededHandling the CellContextMenuStripNeeded event is primarily useful when working with large amounts of data to avoid performance penalties when setting the cell ContextMenuStrip value for multiple cells. 如需詳細資訊,請參閱 縮放 Windows Form DataGridView 控制項的最佳做法For more information, see Best Practices for Scaling the Windows Forms DataGridView Control.

變更這個屬性會在CellContextMenuStripChanged擁有DataGridView的上引發事件(如果有的話)。Changing this property raises the CellContextMenuStripChanged event on the owning DataGridView, if one exists.

您也可以藉由設定 [資料列ContextMenuStrip ] 屬性或DataGridView處理控制項的RowContextMenuStripNeeded事件,指定個別資料列的快捷方式功能表,而不是個別的資料格。You can also specify shortcut menus for individual rows rather than individual cells by setting the row ContextMenuStrip property or handling the DataGridView control's RowContextMenuStripNeeded event. 資料格ContextMenuStrip屬性設定會覆寫ContextMenuStrip row CellContextMenuStripNeeded屬性設定,而事件會覆寫RowContextMenuStripNeeded事件和資料列ContextMenuStrip屬性設定。The cell ContextMenuStrip property setting overrides the row ContextMenuStrip property setting, and the CellContextMenuStripNeeded event overrides both the RowContextMenuStripNeeded event and the row ContextMenuStrip property setting. 不過,您null可以針對資料格快捷方式功能表指定,以防止覆寫資料列快捷方式功能表。You can specify null for a cell shortcut menu, however, to prevent a row shortcut menu from being overridden.

適用於

另請參閱