DataGridViewRowContextMenuStripNeededEventArgs.ContextMenuStrip Özellik

Tanım

Olayı tetikleyen RowContextMenuStripNeeded satırın kısayol menüsünü alır veya ayarlar.

C#
public System.Windows.Forms.ContextMenuStrip ContextMenuStrip { get; set; }
C#
public System.Windows.Forms.ContextMenuStrip? ContextMenuStrip { get; set; }

Özellik Değeri

ContextMenuStrip Kullanımda.

Örnekler

Aşağıdaki kod örneği, çalışanın RowContextMenuStripNeeded unvanını temel alan bir ContextMenuStrip sağlamak için olayı işler. Bu örnekte, biri yöneticiler ve diğeri diğer tüm çalışanlar için iki kısayol menüsü vardır. Bu örnek, sınıfa genel bakış bölümünde DataGridViewRowContextMenuStripNeededEventArgs bulunan daha büyük bir örneğin bir parçasıdır.

C#
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;
}

Açıklamalar

Bu özellik başlangıçta bir satır için ayarlanmışsa özelliğinin DataGridViewRow.ContextMenuStrip değerini içerir.

Şunlara uygulanır

Ürün Sürümler
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Ayrıca bkz.