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.

GetInheritedContextMenuStrip 方法传递用于检索 DataGridViewCell的行索引。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.

适用于

另请参阅