Share via


ListObject.BeforeRightClick Event

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

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)

Syntax

'Declaration
Event BeforeRightClick As DocEvents_BeforeRightClickEventHandler
event DocEvents_BeforeRightClickEventHandler BeforeRightClick

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.

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

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

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

.NET Framework Security

See Also

Reference

ListObject Interface

Microsoft.Office.Tools.Excel Namespace