Active Query Builder support area

How to add or remove some of the context menu items? (Winforms Edition 2.0)

Last modified:


To modify the component's context popup menus, you must handle the ValidateContextMenu event. The following example demonstrates the addition of a custom menu item in the context menu of data source object.
using ActiveDatabaseSoftware.ActiveQueryBuilder2;

public partial class Form1 : Form
{

    public Form1()
    {
        InitializeComponent();
        this.queryBuilder1.ValidateContextMenu += new PopupMenuEventHandler(this.ValidateContextMenu);
    }

    private void ValidateContextMenu(Control control, ControlOwner owner, ICustomContextMenu menu)
    {
        // check the menu is from the datasource object
        if (control is DataSourceControl && owner is DataSourceObject)
        {
            // Here you can freely modify the menu adding or removing menu items.
            MenuItem mi = menu.MenuItems.Add("Custom Menu Item", new EventHandler(MenuItem_Click));
            mi.Tag = owner;
        }
    }

    void MenuItem_Click(object sender, EventArgs e)
    {
        DataSourceObject dso = (DataSourceObject)((MenuItem)sender).Tag;
        if (dso.MetadataObject != null)
        {
            MessageBox.Show(dso.MetadataObject.FullNameStr);
        }
    }
}
The controlOwner parameter refers to the query object for which the context menu is called. The control parameter refers to the control representing this query object. The following combinations are possible:
  • controlOwner is Link; control is LinkControl.
  • controlOwner is DataSourceObject or DataSourceQuery; control is DataSourceControl.
  • controlOwner is QueryColumnListItem; control is QueryColumnListControl.
  • controlOwner is UnionSubQuery; control is DesignPane: design pane context menu.
  • controlOwner is UnionSubQuery; control is UnionButton: context menu of the union button ("Q" button on the navigation bar).
  • controlOwner is UnionSubQuery; control is UnionOperator: context menu of the union operator (union type symbol on the navigation bar).
  • controlOwner is UnionGroup; control is LeftBracket: context menu of the left bracket ("(" symbol on the navigation bar).
  • controlOwner is UnionGroup; control is RightBracket: context menu of the right bracket (")" symbol on the navigation bar).

Is this article helpful for you?