HomeActive Query Builder - HowTos and TroubleshootingUser Interface CustomizationHow to modify context menus?

1.2. How to modify context menus?

To modify the component's context popup menus you need to handle the ValidateContextMenu event. The following example demonstrates adding of a custom menu item in the context menu of data source object.

using ActiveDatabaseSoftware.ActiveQueryBuilder;

public partial class Form1 : Form
{

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

	private void ValidateContextMenu(Control control, ControlOwner owner, ContextMenu 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 CriteriaItem; control is CriteriaListControl.
  • controlOwner is UnionSubQuery; control is DiagramPane: diagram 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).

This page was: Helpful | Not Helpful