Hide

SftTree/NET 2.0 - Tree Control for Windows Forms

Display
Print

RecalcHorizontalExtent Method, SftTree Class

Recalculates the optimal horizontal scrolling extent.

Class: SftTree
Namespace: Softelvdm.SftTreeNET
Assembly: Softelvdm.SftTreeNET

Syntax

public void RecalcHorizontalExtent();
Public Sub RecalcHorizontalExtent()

Comments

Recalculates the optimal horizontal scrolling extent.

By default, a tree control does not handle horizontal scrolling, even if the SftTree.ScrollbarHorizontal property defines scroll bars to be available. To start horizontal scrolling, an application has to use the ColumnClass.MakeOptimal (or ColumnsClass.MakeOptimal) first. This calculates the optimal width for each (or all columns). Then RecalcHorizontalExtent or the SftTree.HorizontalExtent property is used to indicate to the tree control that horizontal scrolling support is desired based on the current column widths.

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 and all properties have been set.

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 ColumnClass.MakeOptimal and RecalcHorizontalExtent method have 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 ColumnsClass.LastOpenended property, the last column can be defined as open-ended. An open-ended last column will display the complete cell contents for the last (or only) displayed 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 (ColumnsClass.LastOpenended)

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 ColumnClass.MakeOptimal (or ColumnsClass.MakeOptimal) RecalcHorizontalExtent method as much as possible. It is best done after all items have been added with all their cells and attributes, because most changes to the tree control can invalidate the optimal horizontal scrolling extent calculated.

When calculating the optimal column widths, each item will be analyzed and its length calculated using the item's cell contents.

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.

Examples

C#

             AddItem(cat, img, "Item cc");
             AddItem(cat, img, "Item dd");
             AddItem(cat, img, "Item ee");
            cat = AddCategory("Category 7");
             AddItem(cat, img, "Item 123");
             AddItem(cat, img, "Item abc");
                        
            sftTree1.Columns.MakeOptimal(0, false);
            sftTree1.RecalcHorizontalExtent();
            sftTree1.Initializing = false;
        }

        private ItemClass AddCategory(string Category) {
            ItemClass item = sftTree1.ItemCollection.Add();
            CellClass cell = item.Cells[0];
            cell.Appearance = BackgroundAppearanceEnum.ThemedSystemHeaderNeverPressed;

VB.NET

     AddItem(cat, img, "Item cc")
     AddItem(cat, img, "Item dd")
     AddItem(cat, img, "Item ee")
    cat = AddCategory("Category 7")
     AddItem(cat, img, "Item 123")
     AddItem(cat, img, "Item abc")

    sftTree1.Columns.MakeOptimal(0, False)
    sftTree1.RecalcHorizontalExtent()
    sftTree1.Initializing = False
End Sub

Private Function AddCategory(ByVal Category As String) As ItemClass
    Dim item As ItemClass = sftTree1.ItemCollection.Add()
    Dim cell As CellClass = item.Cells(0)
    cell.Appearance = BackgroundAppearanceEnum.ThemedSystemHeaderNeverPressed

See Also SftTree Class | Classes | SftTree/NET 2.0