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 rowIndex 参数。Do 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.