ListObject.BeforeRightClick Event

Definition

Occurs when the ListObject control is right-clicked, before the default right-click action.

public:
 event Microsoft::Office::Interop::Excel::DocEvents_BeforeRightClickEventHandler ^ BeforeRightClick;
event Microsoft.Office.Interop.Excel.DocEvents_BeforeRightClickEventHandler BeforeRightClick;
member this.BeforeRightClick : Microsoft.Office.Interop.Excel.DocEvents_BeforeRightClickEventHandler 
Event BeforeRightClick As DocEvents_BeforeRightClickEventHandler 

Event Type

Examples

The following code example creates a ListObject and a BeforeRightClick event handler. When the list object is right-clicked, a message is displayed that indicates whether the list object is bound to data.

This version is for a document-level customization.

Microsoft.Office.Tools.Excel.ListObject list3;
private void ListObject_BeforeRightClick()
{
    list3 = this.Controls.AddListObject(
        this.Range["A1", "C4"], "list3");
    list3.BeforeRightClick += new 
        Microsoft.Office.Interop.Excel.
        DocEvents_BeforeRightClickEventHandler(
        list3_BeforeRightClick);
}

void list3_BeforeRightClick(Microsoft.Office.Interop.Excel.Range 
    Target, ref bool Cancel)
{
    MessageBox.Show("Data binding is " + list3.IsBinding);
    Cancel = true;
}
WithEvents List3 As Microsoft.Office.Tools.Excel.ListObject

Private Sub ListObject_BeforeRightClick()
    List3 = Me.Controls.AddListObject( _
        Me.Range("A1", "C4"), "List3")
End Sub


Sub List3_BeforeRightClick(ByVal Target As _
    Microsoft.Office.Interop.Excel.Range, _
    ByRef Cancel As Boolean) Handles List3.BeforeRightClick
    MessageBox.Show("Data binding is " & List3.IsBinding)
    Cancel = True
End Sub

This version is for an application-level add-in.

ListObject list3;
private void ListObject_BeforeRightClick()
{
    Worksheet vstoWorksheet = 
        Globals.Factory.GetVstoObject(this.Application.ActiveWorkbook.Worksheets[1]);
    list3 = vstoWorksheet.Controls.AddListObject(
        vstoWorksheet.Range["A1", "C4"], "list3");
    list3.BeforeRightClick += new
        Excel.DocEvents_BeforeRightClickEventHandler(
        list3_BeforeRightClick);
}

void list3_BeforeRightClick(Microsoft.Office.Interop.Excel.Range
    Target, ref bool Cancel)
{
    System.Windows.Forms.MessageBox.Show("Data binding is " + list3.IsBinding);
    Cancel = true;
}
WithEvents List3 As ListObject

Private Sub ListObject_BeforeRightClick()
    Dim NativeWorksheet As Microsoft.Office.Interop.Excel.Worksheet =
        Me.Application.Worksheets(1)
    Dim vstoWorksheet As Microsoft.Office.Tools.Excel.Worksheet =
            Globals.Factory.GetVstoObject(NativeWorksheet)
    List3 = vstoWorksheet.Controls.AddListObject( _
        vstoWorksheet.Range("A1", "C4"), "List3")
End Sub


Sub List3_BeforeRightClick(ByVal Target As  _
    Microsoft.Office.Interop.Excel.Range, _
    ByRef Cancel As Boolean) Handles List3.BeforeRightClick
    System.Windows.Forms.MessageBox.Show("Data binding is " & List3.IsBinding)
    Cancel = True
End Sub

Applies to