Cube Tree Structure items: custom drawing
Posted by - NA - on 02 March 2009 10:14 AM

Abstract

Sometimes we need to display elements of the Cube Tree Structure in a different way: for example, mark out the used or recommended elements.

Content

You can override the drawing of the Tree Structure elements in the TOLAPGrid.OnDrawTreeNode event.

The OnDrawTreeNode event argument’s properties:
TEventDrawTreeNodeArgs.DrawDefault — defines the type of drawing (standard or custom). If set to False, there will be no standard drawing of the Tree element.
TEventDrawTreeNodeArgs.IsUsing — the Tree element was used in pivot-panels
TEventDrawTreeNodeArgs.Graphics — a Graphics type object for the custom drawing
TEventDrawTreeNodeArgs.Node — the element to be drawn
TEventDrawTreeNodeArgs.Data — node data (measure, hierarchy, etc)

There are three ways of drawing a Tree

1. Default Drawing

    Applied when:
  • no additional operations with the OnDrawTreeNode or the CubeStructureTree are performed
  • the flag e.DrawDefault = true in the OnDrawTreeNode event handler and the default TOLAPGrid.CubeStructureTree.DrawMode == TreeViewDrawMode.OwnerDrawText is kept unchanged
  • if TOLAPGrid.CubeStructureTree.DrawMode == TreeViewDrawMode.Normal the event handler will not be called

2. Text Amended Drawing

    You can change the text of the Tree nodes. For that, you need:
  • Set the property value TOLAPGrid.CubeStructureTree.DrawMode == TreeViewDrawMode.OwnerDrawText
  • In the OnDrawTreeNode event handler, draw the text of the Tree node.
Note: the property e.Bounds of the event argument returns a rectangle with the node text.

3. Custom Drawing of the Text and Other Elements of the Node

    For the fully custom drawing of the Tree nodes you need:
  • Set the value TOLAPGrid.CubeStructureTree.DrawMode == TreeViewDrawMode.OwnerDrawAll
  • In the event handler OnDrawTreeNode, draw all the elements of the Tree node. Note: the property e.Bounds of the event argument returns a rectangle with the node.
Note: if in the event handler set the flag e.DrawDefault = true, the default drawing will be performed.

By default the custom drawing text mode is set for the TOLAPGrid.CubeStructureTree object (TOLAPGrid.CubeStructureTree.DrawMode == TreeViewDrawMode.OwnerDrawText). You can change the drawing mode through the Tree’s property: TOLAPGrid.CubeStructureTree.DrawMode == TreeViewDrawMode.OwnerDrawText

An example of the event handler: the already used dimensions will be displayed in bold red letters, and the already used hierarchies – in bold light-yellow letters.

void Grid_OnDrawTreeNode(object Sender, TEventDrawTreeNodeArgs e)
{
    e.DrawDefault = true;

    if (e.IsUsing)
    {
        e.DrawDefault = false;
        Brush brush = new SolidBrush(Color.Red);
        if (e.Data is THierarchy)
            brush = new SolidBrush(Color.Lime);
        Font font = new Font(Grid.CubeStructureTree.Font, FontStyle.Bold);
        e.Graphics.DrawString(e.Node.Text, font, brush, e.Bounds.Location);
    }
}

In the derived objects of the TOLAPGrid, for the better control over the drawing process, you can reload the protected method: TOLAPGrid.DrawTreeNode(TEventDrawTreeNodeArgs e)

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

Help Desk Software by Kayako Resolve