Hide

SftTree/OCX 7.5 - ActiveX Tree Control

Display
Print

MakeOptimal Method, SftTreeColumns Object

Sets the optimal column width of all columns so that the text and graphics of all items can be displayed without being clipped horizontally.

Syntax

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

object

A SftTreeColumns object.

Comments

The MakeOptimal method sets the optimal column width of all columns so that the text and graphics of all items can be displayed without being clipped horizontally.

This method resizes all columns to their optimal widths so that the column headers and each cell can be completely displayed without being truncated or clipped. The Column.OptimalWidth method can be used to calculate a column's optimal width without resizing the column. The column width can be changed using the Column.Width property.

The Column.MakeOptimal method can be used to set the optimal column width of just one column.

By changing tree control properties, the optimal column width may change. Adding items, setting new cell graphics and changing cell text are a few of the actions that can affect the optimal column width. The column width may have to be set again to allow items to be completely visible.

The tree control does not automatically adjust column widths.

Cells which merge into an adjacent column are not considered when calculating the optimal column width.

The last (or only) column may be an "open-ended" column. If the ColumnsObj.OpenEnded property is set to True, the last displayed column will always use the space remaining between the previous column and the right edge of the tree control window.

Calculating the optimal column width can be a time consuming operation, particularly if many items have been added to the tree control. The Items.CalcLimit property can be used to limit the maximum number of items to consider for optimal column width calculation. MakeOptimal 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.

If items are not visible because their parent items are collapsed, these can be excluded from the optimal width calculation by setting the Items.CalcVisibleOnly property to True.

Examples

VB.NET

    Item.MaxHeightPix = 300 ' always exactly 300 pixels

    ' Form
    Dim f As FormSmall = New FormSmall()
    AxSftTree1.get_Item(6).Cell(1).AttachContentWindow(f.Handle, SftTreeContentWindowStyleConstants.contentWindowSftTreeKeepSize)
    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

VB6

    Set Item = SftTree1.Item(5)
    Set Cell = Item.Cell(1)
    Cell.AttachContentWindow WebBrowserPictureBox.hWnd, contentWindowSftTreeNone
    Cell.Text = ""
    Item.MinHeightPix = 300 ' always exactly 300 pixels
    Item.MaxHeightPix = 300 ' always exactly 300 pixels

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

    ' 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

C#

            Item.MaxHeightPix = 300; // always exactly 300 pixels

            // Form
            FormSmall f = new FormSmall();
            axSftTree1.get_Item(6).get_Cell(1).AttachContentWindow((long)f.Handle, SftTreeContentWindowStyleConstants.contentWindowSftTreeKeepSize);
            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

C++

    // Create the dialog
    m_SimpleDialog.Create(IDD_SIMPLEDIALOG, &m_Tree);

    m_vTree->Item[6]->Cell[1]->Text = _T("");
    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;

See Also SftTreeColumns Object | Object Hierarchy


Last Updated 08/13/2020 - (email)
© 2024 Softel vdm, Inc.


Spring Break!

Our offices will be closed this week (March 18 through March 22).

We'll be back March 24 to address any pending sales and support issues.