DataGridViewCell.GetInheritedContextMenuStrip(Int32) 方法


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

 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



目前儲存格的資料列索引。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.

GetInheritedContextMenuStrip將您用來取得的資料列索引傳遞給方法 DataGridViewCellPass the GetInheritedContextMenuStrip method the row index you used to retrieve the DataGridViewCell. 請勿使用參數的 RowIndex 屬性 rowIndexDo not use the RowIndex property for the rowIndex parameter. 如果資料列是共用的, RowIndex 則為-1,這不是的有效值 rowIndexIf the row is shared, RowIndex is -1, which is not a valid value for rowIndex.