DataGridViewRowContextMenuStripNeededEventArgs.RowIndex Property
Gets the index of the row that is requesting a shortcut menu.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
The following code example handles the RowContextMenuStripNeeded event to provide a ContextMenuStrip based on the title of the employee. In this example, there are two shortcut menus, one for managers and one for all other employees. This example is part of a larger example available in the DataGridViewRowContextMenuStripNeededEventArgs class overview.
void dataGridView1_RowContextMenuStripNeeded(object sender, DataGridViewRowContextMenuStripNeededEventArgs e) { DataGridViewRow dataGridViewRow1 = dataGridView1.Rows[e.RowIndex]; toolStripMenuItem1.Enabled = true; // Show the appropriate ContextMenuStrip based on the employees title. if ((dataGridViewRow1.Cells["Title"].Value.ToString() == "Sales Manager") || (dataGridViewRow1.Cells["Title"].Value.ToString() == "Vice President, Sales")) { e.ContextMenuStrip = managerMenuStrip; } else { e.ContextMenuStrip = employeeMenuStrip; } contextMenuRowIndex = e.RowIndex; }
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.