DataGridViewCell.GetInheritedContextMenuStrip(Int32) 方法

定義

取得目前儲存格的繼承捷徑功能表。Gets the inherited shortcut menu for the current cell.

public:
 virtual System::Windows::Forms::ContextMenuStrip ^ GetInheritedContextMenuStrip(int rowIndex);
public virtual System.Windows.Forms.ContextMenuStrip GetInheritedContextMenuStrip (int rowIndex);
abstract member GetInheritedContextMenuStrip : int -> System.Windows.Forms.ContextMenuStrip
override this.GetInheritedContextMenuStrip : int -> System.Windows.Forms.ContextMenuStrip
Public Overridable Function GetInheritedContextMenuStrip (rowIndex As Integer) As ContextMenuStrip

參數

rowIndex
Int32

目前儲存格的資料列索引。The row index of the current cell.

傳回

如果父 ContextMenuStripDataGridViewDataGridViewRow 已指定 DataGridViewColumn,則為 ContextMenuStrip,否則為 nullA ContextMenuStrip if the parent DataGridView, DataGridViewRow, or DataGridViewColumn has a ContextMenuStrip assigned; otherwise, null.

例外狀況

儲存格的 DataGridView 屬性值不是 null,而且指定的 rowIndex 小於 0 或大於控制項中的資料列數減去 1。The value of the DataGridView property of the cell is not null and the specified rowIndex is less than 0 or greater than the number of rows in the control minus 1.

ColumnIndex 小於 0,表示儲存格是資料列行首儲存格。ColumnIndex is less than 0, indicating that the cell is a row header cell.

備註

如果資料格沒有相關聯的 ContextMenuStrip,它會使用下列優先順序從其父代繼承一個:If the cell does not have an associated ContextMenuStrip, it will inherit one from its parents, using the following precedence:

  1. 此儲存格的 ContextMenuStripThis cell's ContextMenuStrip

  2. 擁有資料列的 DataGridViewRow.ContextMenuStripThe owning row's DataGridViewRow.ContextMenuStrip

  3. 擁有資料行的 DataGridViewColumn.ContextMenuStripThe owning column's DataGridViewColumn.ContextMenuStrip

  4. 父資料表的 System.Windows.Forms.ContextMenuStripThe parent table's System.Windows.Forms.ContextMenuStrip

快捷方式功能表是 Microsoft Windows 原生資源,其存留期通常是由 Dispose 方法或析構函式所導向。Shortcut menus are Microsoft Windows native resources whose lifetimes are typically directed by the Dispose method or the destructor.

將您用來抓取 DataGridViewCell的資料列索引傳遞給 GetInheritedContextMenuStrip 方法。Pass the GetInheritedContextMenuStrip method the row index you used to retrieve the DataGridViewCell. 請不要使用 rowIndex 參數的 RowIndex 屬性。Do not use the RowIndex property for the rowIndex parameter. 如果資料列是共用的,RowIndex 為-1,這對 rowIndex而言不是有效的值。If the row is shared, RowIndex is -1, which is not a valid value for rowIndex.

適用於

另請參閱