SftTree/OCX 7.5 Documentation

Display
Print

RecalcHorizontalExtent Method, SftTreeItems Object

Recalculates the optimal horizontal scrolling extent.

Syntax

VB.NETobject.RecalcHorizontalExtent()
VBobject.RecalcHorizontalExtent
C#.NETvoid object.RecalcHorizontalExtent();
VC++HRESULT object->RecalcHorizontalExtent();
CHRESULT object->raw_RecalcHorizontalExtent();

object

A SftTreeItems object.

Comments

The RecalcHorizontalExtent method recalculates the optimal horizontal scrolling extent.

By default, a tree control does not handle horizontal scrolling, even if the Scrollbars property defines scroll bars to be available. To start horizontal scrolling, an application has to use the RecalcHorizontalExtent method or the Items.HorizontalExtent property. They indicate to the tree control that horizontal scrolling support is desired and allows it to determine the horizontal scrolling extent. Once the horizontal scrolling extent has been set, many tree control methods and properties may invalidate the horizontal extent. E.g., adding a new item may invalidate the extent, so it is best to delay using the RecalcHorizontalExtent method until after all items have been added, all properties have been set and the column widths have been defined.

The tree control doesn't automatically update the horizontal extent when items are added or deleted or other methods or properties are used, which may invalidate the horizontal extent. The RecalcHorizontalExtent method has to be used again to recalculate the extent.

Based on the definition of the last column, different algorithms are used to calculate the optimal scrolling extent. Using the ColumnsObj.OpenEnded property, the last column can be defined as open-ended, which is the default if the application doesn't define any columns. An open-ended last column will display the complete text and graphics specified for the last (or only) column and never truncate any data. A fixed-width last column is defined with a specified width and any data which doesn't fit is truncated.

Open-Ended Last Column

Recalculating the best horizontal scrolling extent can be a costly operation (in terms of elapsed time). When updating a tree control, it is best to delay using the RecalcHorizontalExtent method as much as possible. It is best done after all items have been added, their levels have been set and all necessary graphics and tree control attributes have been defined, because most changes to the tree control can invalidate the optimal horizontal scrolling extent calculated.

When calculating the optimal scrolling extent, each item will be analyzed and its length calculated using the item's text and graphic components and its level. The widest item determines the horizontal scrolling extent.

Calculating the optimal horizontal extent can be a time consuming operation, particularly if many items have been added to the tree control. RecalcHorizontalExtent scans all items to determine the best column width, but can be limited to a specific number of items using the Items.CalcLimit property. This reduces the time spent to calculate the optimal width, but may still leave some items clipped.

Fixed-Width Last Column

Recalculating the best horizontal scrolling extent is a very quick operation. The width of all columns and some initial overhead (based on the highest level number found) is calculated to determine the horizontal scrolling extent. No cell text is analyzed.

Examples

VB.NET

    AxSftTree1.get_Item(6).Cell(1).Text = ""

    AxSftTree1.RowHeaders.MakeOptimal() ' Make row header width optimal, so text and pictures are not clipped horizontally.
    AxSftTree1.ColumnsObj.MakeOptimal() ' Make all columns optimal

    ' triple the size of the last column
    AxSftTree1.get_Column(1).WidthPix = AxSftTree1.get_Column(1).WidthPix * 3

    AxSftTree1.Items.RecalcHorizontalExtent() ' Update horizontal scrollbar

    AxSftTree1.Items.Current = 0 ' select the first item
    AxSftTree1.get_Item(0).Selected = True

    AxSftTree1.Dock = DockStyle.Fill ' Maximize the main window

    Me.WindowState = FormWindowState.Maximized

VB6

    ' Form
    Set SavedForm = New Form2
    SftTree1.Item(6).Cell(1).AttachContentWindow SavedForm.hWnd, contentWindowSftTreeKeepSize
    SftTree1.Item(6).Cell(1).Text = ""

    ' triple the size of the last column
    SftTree1.Column(1).WidthPix = SftTree1.Column(1).WidthPix * 3

    SftTree1.Items.RecalcHorizontalExtent ' Update horizontal scrollbar

    SftTree1.Items.Current = 0 ' select the first item
    SftTree1.Item(0).Selected = True

    Me.WindowState = 2 ' Maximize the main window
End Sub

C#

            axSftTree1.get_Item(6).get_Cell(1).Text = "";

            axSftTree1.RowHeaders.MakeOptimal(); // Make row header width optimal, so text and pictures are not clipped horizontally.
            axSftTree1.ColumnsObj.MakeOptimal(); // Make all columns optimal

            // triple the size of the last column
            axSftTree1.get_Column(1).WidthPix = axSftTree1.get_Column(1).WidthPix * 3;

            axSftTree1.Items.RecalcHorizontalExtent(); // Update horizontal scrollbar

            axSftTree1.Items.Current = 0; // select the first item
            axSftTree1.get_Item(0).Selected = true;

            axSftTree1.Dock = DockStyle.Fill; // Maximize the main window

            this.WindowState = FormWindowState.Maximized;

C++

    m_vTree->Item[6]->Cell[1]->AttachContentWindow((int) m_SimpleDialog.m_hWnd, contentWindowSftTreeKeepSize);

    m_vTree->RowHeaders->MakeOptimal(); // Make row header width optimal, so text and pictures are not clipped horizontally.
    m_vTree->ColumnsObj->MakeOptimal(); // Make all columns optimal

    // triple the size of the last column
    m_vTree->Column[1]->WidthPix = m_vTree->Column[1]->WidthPix * 3;

    m_vTree->Items->RecalcHorizontalExtent(); // Update horizontal scrollbar

    m_vTree->Items->Current = 0; // select the first item
    m_vTree->Item[0]->Selected = VARIANT_TRUE;

    SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, 0);

    return TRUE;  // return TRUE  unless you set the focus to a control

See Also SftTreeItems Object | Object Hierarchy


Last Updated 04/28/2018 - (email)
© 2018 Softel vdm, Inc.