Hide

SftTree/NET 2.0 - Tree Control for Windows Forms

Display
Print

MakeOptimal Method, ColumnsClass Class

Sets the optimal column width of all columns so that the cell contents of all cells can be displayed without being clipped horizontally.

Class: ColumnsClass
Namespace: Softelvdm.SftTreeNET
Assembly: Softelvdm.SftTreeNET

Syntax

public void MakeOptimal(
    int MaxScan,
    bool VisibleOnly );
public void MakeOptimal(
    int MaxScan,
    bool VisibleOnly,
    bool Headers,
    bool Items,
    bool Footers );
Public Sub MakeOptimal(
    ByVal MaxScan As Integer,
    ByVal VisibleOnly As Boolean )
Public Sub MakeOptimal(
    ByVal MaxScan As Integer,
    ByVal VisibleOnly As Boolean,
    ByVal Headers As Boolean,
    ByVal Items As Boolean,
    ByVal Footers As Boolean )

Parameters

MaxScan

Defines the maximum number of items to scan to determine the optimal column width or 0 to scan all items.

VisibleOnly

Defines whether only visible items should be considered to determine the optimal column width. Visible items are items whose parent items are expanded.

Headers

Defines whether the column headers should be considered to determine the optimal column width. The default is True.

Items

Defines whether the items should be considered to determine the optimal column width. The default is True.

Footers

Defines whether the column footers should be considered to determine the optimal column width. The default is True.

Comments

Sets the optimal column width of all columns so that the cell contents of all cells can be displayed without being clipped horizontally.

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

The ColumnClass.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 contents are a few of the actions that can affect the optimal column width. The column width may have to be set again to allow cells 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 ColumnsClass.LastOpenended 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 MaxScan parameter 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 MaxScan parameter. 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 VisibleOnly parameter to True.

Examples

C#

             AddItem(cat, img, "Item bb");
             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];

VB.NET

     AddItem(cat, img, "Item bb")
     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)

See Also ColumnsClass Class | Classes | SftTree/NET 2.0