Search
English
Custom menus in RIA controls

In the 2.02 version in RIA controls you are now able to edit the context menu of the Grid and Chart cells.

You can do that by handling the OnShowContextMenu and OnContextMenuClick events of the RiaOLAPGrid or RiaOLAPChart controls.

The first one lets you edit contents of the default context menu (add your own menu items, and edit or even delete the existing ones).

A context menu item is represented by the TGenericMenuItem class. Below is the description of its basic properties:

PropertyDescription
ActionTypeSet is compulsory!
For TGenericMenuItems, created in the OnShowContextMenu events handler, this property must be set into CustomAction (with the exception of menu items with children – in this case it should be Nothing).
CaptionSet is compulsory!
A caption of the context menu item.
ChildItemsThe list of “children” menu items – in this case, the menu is multi-level.
HandlingTypeSet is compulsory!
The menu item click handling type: it can be handled on the server through a Callback-request (AJAX), Postback-request, or a client-side JScript function can be called (ClientOnly).
IsCheckedTrue or False, depending of the required status of the “Checked” menu item.
MenuItemValueFor the Callback and Postback handling types – the unique value, passed to the OnContextMenuClick event handler, that allows identifying which menu item was clicked.
ClientScriptFor the ClientOnly handling type – the JScript-function to be called.

The most complicated of them is the HandlingType property. The value of this property is selected in accordance with the following criteria:

  1. If a click on this menu item calls a client JScript-function, this item’s value is set to ClientOnly, and the calling code is written in the ClientScript property.
  2. If a click on this menu item is handled on the server, and nothing, except the Grid state, is changed, you should use the “Callback” type.
  3. If by a click on this menu item, the state of other objects on the web-page is changed, or files are passed to the client (or any other action incompatible with the asynchronous request takes place), you should use the “Postback” type.

In the example below, you can find realization of all three types of menu items:

// The OnShowContextMenu event handler
protected void TOLAPGrid1_OnShowContextMenu(object sender, ShowRIAContextMenuEventArgs e)
{
TGenericMenuItem mi = new TGenericMenuItem();

    // for custom context menu items ActionType property should be set to the CustomAction
    mi.ActionType = TGenericMenuActionType.CustomAction;
    mi.Caption = "Toggle Grid";
    // Since only the Grid contains are changed, it is possible to use the Callback-mode
    mi.HandlingType = TClientActionHandlingType.Callback;
    mi.IsChecked = false;
    mi.MenuItemValue = "Toggle";

    e.ContextMenu.Add(mi);

    mi = new TGenericMenuItem();
    // for custom context menu items ActionType property should be set to the CustomAction
    mi.ActionType = TGenericMenuActionType.CustomAction;
    mi.Caption = "Export to XLS";
    // Export operation. A file is passed to the client, hence the use of callback is impossible.
    // We'll use the postback instead.
    mi.HandlingType = TClientActionHandlingType.Postback;
    mi.IsChecked = false;
    mi.MenuItemValue = "Export";

    e.ContextMenu.Add(mi);

    mi = new TGenericMenuItem();
    // for custom context menu items ActionType property should be set to the CustomAction
    mi.ActionType = TGenericMenuActionType.CustomAction;
    mi.Caption = "Show alert";
    // Call of the JScript-function. So the handling type - ClientOnly.
    mi.HandlingType = TClientActionHandlingType.ClientOnly;
    mi.IsChecked = false;
    mi.ClientScript = "alert('The menu item is clicked');";

    e.ContextMenu.Add(mi)

}
&
// The OnContextMenuClick event handler
protected void TOLAPGrid1_OnContextMenuClick(object sender, ContextMenuClickArgs e)
{
    if (e.MenuItemValue == "Toggle")
        TOLAPGrid1.ToggleLayout();

    if (e.MenuItemValue == "Export")
{
        Response.ContentType = "APPLICATION/OCTET-STREAM";
        Response.AppendHeader("Content-Disposition", "Attachment; Filename=export.xls");
        TOLAPGrid1.Export.ExportTo(Page.Response.OutputStream, TConvertType.ctXLS);
        Response.End();
    }
}

For an end user the menu with the added items will look like this:

Related links

Download Radar-Soft products


Buy Radar-Soft products


Visit our support site


Hot news
Click to subscribe

 July 22, 2010

RadarCube for WPF beta is here

The new RadarCube for WPF version has started.

Details...

 

Latest versions
Click to subscribe

 July 14, 2010

RadarCube ASP.NET 2.44.3

Changes...Download...

 

 June 25, 2010

RadarCube WinForms Desktop 2.31.0

Changes...Download...

 

 June 25, 2010

RadarCube WinForms MSAS 2.31.0

Changes...Download...

 

 May 20, 2010

RadarCube VCL 1.18.0

Changes...Download...

 

 April 22, 2010

HierCube VCL 4.56.0

Changes...Download...

 

 July 15, 2009

Essential Pack Pro for ASP.NET 1.11.0

Changes...Download...

 

 July 15, 2009

Essential Pack for ASP.NET 1.11.0

Changes...Download...

 

 November 5, 2008

WinForms Chart 1.00.1

Changes...Download...

 

Related articles
Click to subscribe

 May 5, 2010

New Silverlight add-on for RadarCube ASP.NET

Details...

 

 March 30, 2010

Designing the Cube with the Cube Creation Wizard

Details...

 

 December 16, 2009

Creating custom Time Intelligence

Details...

 

 November 26, 2009

Creating the correct Cube structure

Details...

 

 September 30, 2009

RadarCube Request tracker

Details...

 

 August 24, 2009

Customizing the toolbox in Ria OLAP controls

Details...
More articles...
Support | Download | Purchase | Partners | Upgrade and Discount Policy | Contacts © 2005-2010 Radar-Soft, L.L.C. All rights reserved.