Managing the Properties of the TToolbox Panel
Posted by - NA - on 27 November 2008 05:36 PM

Overriding Toolbox actions

One of the tasks most often performed while working with OLAP Toolbox is overriding standard actions upon pressing buttons. To do that, you need to handle the TOLAPGrid.ClickToolboxButton event. By examining the e.ItemType property in this event's handler, you can find out what button the user has pressed.

For example, if there's a need to save the Grid state to the data base upon pressing the "Save" button in the toolbox (instead of the standard saving into a file), it can be done with the following code:

RadarSoft.WinForms.Grid.TOLAPGrid grid;
grid.ClickToolboxButton += new RadarSoft.WinForms.ClickToolboxButtonsEventHandler(ClickToolboxButton_handler);

void ClickToolboxButton_handler(object sender, RadarSoft.WinForms.ClickToolboxButtonEventArgs e)
{
    if (e.ItemType == RadarSoft.WinForms.ToolboxButtons.SaveAll)
    {
        SaveToDatabase(Grid.Serializer.XMLString);
        e.Handled = true;
    }
}

Adding Custom Buttons

The TOLAPControlGeneral.Toolbox property provides an access to the panel of tools buttons of the Grid.
The example shows how to add a button called "Sample Button" with the Sample_EventHandler to the set of panel’s buttons.

ToolStripButton sampleButton = new ToolStripButton();
sampleButton.Text = "Sample button";
sampleButton.Click += new EventHandler(Sample_EventHandler);
GridTable.Toolbox.Items.Add(sampleButton);

Toolbox with the added button

Managing the Buttons’ Properties

To manage the buttons’ property, you need to specify the TOLAPControlGeneral.ShowToolboxButton event handler, make sure that its e.ItemType argument’s field contains the button’s code (type), and change the appropriate property, available through e.Item.

This event handler is executed when it is assigned (the first call) and upon changing the Grid state.

Example:
The example code makes the PrintPreview and ZoomGroup buttons unavailable and hides the Palette, Skin and PanelsGroup buttons.

GridTable.ShowToolboxButton += new ShowToolboxButtonEventHandler(GridChart_ShowToolboxButton);

void GridChart_ShowToolboxButton(object sender, ShowToolboxButtonEventArgs e)
{
    switch (e.ItemType)
    {
        case ToolboxButtons.PrintPreview:
        case ToolboxButtons.ZoomGroup:
            e.Item.Visible = true;
            e.Item.Enabled = false;
            break;
        case ToolboxButtons.ApplyPalette:
        case ToolboxButtons.ApplySkin:
        case ToolboxButtons.PanelsGroup:
            e.Item.Visible = false;
            break;
    }
}

Standard view of the toolbox.

The view of the toolbox after using the event handler.

To refresh the buttons’ properties, you need to call the TOLAPControlGeneral.RefreshToolboxItems() manually. This will cause the execution of the TOLAPControlGeneral.ShowToolboxButton event handler for all the Grid’s buttons.

Calling the Toolbox Commands

The toolbox commands are called through the TOLAPControlGeneral.ToolboxCallCommand(ToolboxButtons AButtons) method with the button’s code (type) passed as a parameter. If the call is successful, the method returns true.

Example: calling the print preview command

GridTable.ToolboxCallCommand(ToolboxButtons.PrintPreview);

Placing the Toolbox Outside the Grid

You can use the toolbox separately from the Grid; that is place on the form an external toolbox as a separate component and set the TToolbox.Grid property (without this property toolbox buttons will be unavailable).
At that, the properties of toolbox buttons will be amended according to the Grid’s settings and its internal toolbox will be hidden. To restore the latter, you need to set the former’s Grid property to null. This will make the external toolbox buttons visible, but unavailable.
The same way a single toolbox may be used with several Grids, connected in turn to each selected Grid.

The view of an external toolbox, not connected to the Grid.

The view of an external toolbox, connected to the Grid.

(555 vote(s))
This article was helpful
This article was not helpful

Help Desk Software by Kayako Resolve