Hide

SftTree/OCX 7.5 - ActiveX Tree Control

Display
Print

Add Method, SftTreeItems Object

Adds a new item at the end of the list.

Syntax

VB.NETItemIndex = object.Add(ByVal Text As String) As Integer
VBItemIndex = object.Add(ByVal Text As String) As Long
C#.NETint ItemIndex = object.Add(string Text);
VC++long ItemIndex = object->Add(_bstr_t Text);
CHRESULT object->raw_Add(BSTR Text, long* ItemIndex);

object

A SftTreeItems object.

Text

The text to be used for the item's first (or only) column.

ItemIndex

Returns the zero-based index of the newly added item.

Comments

The Add method adds a new item at the end of the list.

New items added using the Items.Add method are always added at the end of the list. By default, new items are added at level 0. Use the Item.Level property to change an item's level. If many items have to be added or inserted, the BulkUpdate property can be used to indicate a mass-update, which is significantly faster.

Once an item has been added, the Cell.Text property can be used to change the text for any of the available columns.

Items can be inserted at a specific location using the Items.Insert method. Items can be deleted using the Items.Remove method.

When a tree control is populated using Items.Add or Items.Insert, the Items.RecalcHorizontalExtent method can be used to have the tree control calculate the optimal horizontal scrolling area so scroll bars are enabled, depending on the Scrollbars property.

If a parent item is collapsed, subsequently adding child items will automatically expand the item.

Examples

VB.NET

        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        AxSftTree1.BulkUpdate = True

        ' Add all screen fonts to the tree control
        Dim ScreenIndex As Integer
        ScreenIndex = AxSftTree1.Items.Add("Fonts")
        AxSftTree1.get_Item(ScreenIndex).Level = 0

        ' display fonts
        Dim Counter As Integer = 0
        Dim ff As FontFamily
        For Each ff In System.Drawing.FontFamily.Families
            ' add font name

VB6

    Dim ScreenIndex As Integer, PrinterIndex As Integer
    Dim C As SftTreeCell

    With SftTree1
        ' Mass-Update
        .BulkUpdate = True

        ' Add all screen fonts to the tree control
        ScreenIndex = .Items.Add("Screen Fonts")
        .Item(ScreenIndex).Level = 0
        ' display screen fonts
        MaxFonts = Screen.FontCount
        ' limit to 20 fonts
        If MaxFonts > 20 Then MaxFonts = 20
        For I = 0 To MaxFonts - 1
            ' add the item

C#

                axSftTree1.Items.RecalcHorizontalExtent();
            }
        }

        private void Form1_Load(object sender, System.EventArgs e) {
            axSftTree1.BulkUpdate = true;

            // Add all screen fonts to the tree control
            int ScreenIndex = axSftTree1.Items.Add("Fonts");
            axSftTree1.get_Item(ScreenIndex).Level = 0;
            // display fonts

            int counter = 0;
            foreach (FontFamily ff in System.Drawing.FontFamily.Families) {
                // add font name
                Font newFont = null;

C++

    memset(&fd, 0, sizeof(fd));
    fd.lpstrName = FontName;
    fd.cySize.int64 = 10 * 10000L; // 10pt font
    fd.sWeight = FW_NORMAL;
    IFontDispPtr pFontDisp;
    HRESULT hr = OleCreateFontIndirect(&fd, IID_IFontDisp, (void**)&pFontDisp);
    if (FAILED(hr)) return;

    long ItemIndex = m_vTree->Items->Add(FontName);
     m_vTree->Item[ItemIndex]->Level = 1;
     m_vTree->Cell[ItemIndex][1]->Text = FontName;
     m_vTree->Cell[ItemIndex][0]->PutRefFont(pFontDisp);

}

/*static*/ int CALLBACK CListFontDlg::FontEnumeratorProc(ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX *lpntme, DWORD FontType, LPARAM lParam)

See Also SftTreeItems Object | Object Hierarchy


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