Hide

SftBox/OCX 5.0 - Combo Box Control

Display
Print

SftBoxItems.RecalcHorizontalExtent Method

Recalculates the optimal horizontal scrolling extent.

Syntax

VB.NETobject.RecalcHorizontalExtent(ByVal MaxScan As Integer)
VBobject.RecalcHorizontalExtent(ByVal MaxScan As Long)
C#.NETvoid object.RecalcHorizontalExtent(int MaxScan);
VC++HRESULT object->RecalcHorizontalExtent(long MaxScan);
CHRESULT object->raw_RecalcHorizontalExtent(long MaxScan);

object

A SftBoxItems object.

MaxScan

The maximum number of items to be evaluated for horizontal scrolling calculation. If 0 is specified, all items will be considered.

Comments

The RecalcHorizontalExtent method recalculates the optimal horizontal scrolling extent.

By default, a combo box control does not handle horizontal scrolling, even if the Scrollbars property defines horizontal 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 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 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 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 Columns.OpenEnded property, the last column can be defined as open-ended. 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 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 control attributes have been defined, because most changes to the 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 control. RecalcHorizontalExtent scans all items to determine the best column width, but can be limited to a specific number of items using the MaxScan argument. 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

    AddBuiltinImage("Enabled Ascending Indicator", SftPictureImageConstants.sftImageSortAsc, 8, 8)
    AddBuiltinImage("Disabled Ascending Indicator", SftPictureImageConstants.sftImageSortAscDisabled, 8, 8)
    AddBuiltinImage("Enabled Descending Indicator", SftPictureImageConstants.sftImageSortDesc, 8, 8)
    AddBuiltinImage("Disabled Descending Indicator", SftPictureImageConstants.sftImageSortDescDisabled, 8, 8)


    AxSftBox1.RowHeaders.MakeOptimal(0) ' make the row headers optimal
    AxSftBox1.get_Column(0).MakeOptimal(0) ' make the first column optimal
    AxSftBox1.Items.RecalcHorizontalExtent(0) ' update horizontal scroll bar

    AxSftBox1.Items.Selection = 0

    CopyImageFromCurrentItem()
End Sub

Private Sub ExpandCollapseItem(ByVal ItemIndex As Long, ByVal Shift As Short)

VB6

        AddBuiltinImage "Enabled Ascending Indicator", sftImageSortAsc, 8, 8
        AddBuiltinImage "Disabled Ascending Indicator", sftImageSortAscDisabled, 8, 8
        AddBuiltinImage "Enabled Descending Indicator", sftImageSortDesc, 8, 8
        AddBuiltinImage "Disabled Descending Indicator", sftImageSortDescDisabled, 8, 8


        .RowHeaders.MakeOptimal 0 ' make the row headers optimal
        .Column(0).MakeOptimal 0 ' make the first column optimal
        .Items.RecalcHorizontalExtent 0 ' update horizontal scroll bar

        .Items.Selection = 0

        CopyImageFromCurrentItem

    End With

C#

    AddBuiltinImage("Enabled Ascending Indicator", SftPictureImageConstants.sftImageSortAsc, 8, 8);
    AddBuiltinImage("Disabled Ascending Indicator", SftPictureImageConstants.sftImageSortAscDisabled, 8, 8);
    AddBuiltinImage("Enabled Descending Indicator", SftPictureImageConstants.sftImageSortDesc, 8, 8);
    AddBuiltinImage("Disabled Descending Indicator", SftPictureImageConstants.sftImageSortDescDisabled, 8, 8);


    axSftBox1.RowHeaders.MakeOptimal(0); // make the row headers optimal
    axSftBox1.get_Column(0).MakeOptimal(0); // make the first column optimal
    axSftBox1.Items.RecalcHorizontalExtent(0); // update horizontal scroll bar

    axSftBox1.Items.Selection = 0;

    CopyImageFromCurrentItem();
}

private void ExpandCollapseItem(int ItemIndex, short Shift)

C++

    AddBuiltinImage(_T("Enabled Ascending Indicator"), sftImageSortAsc, 8, 8);
    AddBuiltinImage(_T("Disabled Ascending Indicator"), sftImageSortAscDisabled, 8, 8);
    AddBuiltinImage(_T("Enabled Descending Indicator"), sftImageSortDesc, 8, 8);
    AddBuiltinImage(_T("Disabled Descending Indicator"), sftImageSortDescDisabled, 8, 8);


    m_vBox->RowHeaders->MakeOptimal(0); // make the row headers optimal
    m_vBox->Column[0]->MakeOptimal(0); // make the first column optimal
    m_vBox->Items->RecalcHorizontalExtent(0); // update horizontal scroll bar

    m_vBox->Items->Selection = 0;

    CopyImageFromCurrentItem();

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

See Also SftBoxItems Object | Object Hierarchy


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