Hide

SftTree/OCX 7.5 - ActiveX Tree Control

Display
Print

Insert Method, SftTreeItems Object

Inserts a new item at the specified index position.

Syntax

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

object

A SftTreeItems object.

AtIndex

The zero-based index of the position where the item will be inserted. If -1 is specified, the item is added at the end of the list.

Text

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

ItemIndex

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

Comments

The Insert method inserts a new item at the specified index position.

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, 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 added at the end of the list by using the Items.Add 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.

Items can also be added using the Items.InsertAfter method.

Examples

VB.NET

        insertAt = AxSftTree1.Items.DropHighlight
        If insertAt < 0 Then Exit Sub
        If e.data.GetFormat(SftOLEClipboardConstants.sftCFText) Then
            Dim lvl As Integer
            lvl = AxSftTree1.get_Item(insertAt).Level
            Dim str As String
            str = e.data.GetData(SftOLEClipboardConstants.sftCFText)
            Dim newItem As Integer
            newItem = AxSftTree1.Items.Insert(insertAt + 1, str)
            AxSftTree1.get_Item(newItem).Level = lvl + 1
        End If
        If e.data.GetFormat(SftOLEClipboardConstants.sftCFDIB) Then
            AxSftTree1.get_Cell(insertAt, 0).Image.Picture = e.data.GetData(SftOLEClipboardConstants.sftCFDIB)
            AxSftTree1.get_Cell(insertAt, 0).ImageHAlign = SftTreeHAlignConstants.halignSftTreeRight
        End If
        If e.data.GetFormat(SftOLEClipboardConstants.sftCFBitmap) Then

VB6

    col0Width = SftTree1.Column(0).Width

    insertAt = SftTree1.Items.DropHighlight
    If insertAt < 0 Then Exit Sub

    If Data.GetFormat(vbCFText) Then
        lvl = SftTree1.Item(insertAt).Level
        str = Data.GetData(vbCFText)
        newItem = SftTree1.Items.Insert(insertAt + 1, str)
        SftTree1.Item(newItem).Level = lvl + 1
    ElseIf Data.GetFormat(vbCFDIB) Then
        Set SftTree1.Cell(insertAt, 0).Image.Picture = Data.GetData(vbCFDIB)
        SftTree1.Cell(insertAt, 0).ImageHAlign = halignSftTreeRight
    ElseIf Data.GetFormat(vbCFFiles) Then
        SftTree1.BulkUpdate = True
        lvl = SftTree1.Item(insertAt).Level

C#

            int horzExtent = axSftTree1.Items.HorizontalExtentPix;
            int firstColumnWidth = axSftTree1.get_Column(0).WidthPix;

            int insertAt = axSftTree1.Items.DropHighlight;
            if (insertAt < 0) return;
            if (e.data.GetFormat((short) SftOLEClipboardConstants.sftCFText)) {
                short lvl = axSftTree1.get_Item(insertAt).Level;
                string str = (string) e.data.GetData(SftOLEClipboardConstants.sftCFText);
                int newItem = axSftTree1.Items.Insert(insertAt + 1, str);
                axSftTree1.get_Item(newItem).Level = (short) (lvl + 1);
            }
            if (e.data.GetFormat((short) SftOLEClipboardConstants.sftCFDIB)) {
                axSftTree1.get_Cell(insertAt, 0).Image.Picture = (stdole.IPictureDisp)e.data.GetData((short) SftOLEClipboardConstants.sftCFDIB);
                axSftTree1.get_Cell(insertAt, 0).ImageHAlign = SftTreeHAlignConstants.halignSftTreeRight;
            }
            if (e.data.GetFormat((short) SftOLEClipboardConstants.sftCFBitmap)) {

C++

    long insertAt = m_vTree->Items->DropHighlight;
    if (insertAt < 0) return;

    if (pDataObject->GetFormat(sftCFText) != VARIANT_FALSE) {
        int lvl = m_vTree->Item[insertAt]->Level;
        _variant_t object = pDataObject->GetData((short)sftCFText);
        _bstr_t astring = object;
        long newItem = m_vTree->Items->Insert(insertAt + 1, astring);
        m_vTree->Item[newItem]->Level = lvl + 1;
    } else if (pDataObject->GetFormat(sftCFDIB)) {
        _variant_t object = pDataObject->GetData((short)sftCFDIB);
        IPictureDispPtr pPicDisp = object;
        m_vTree->Cell[insertAt][0]->Image->PutRefPicture(pPicDisp);
        m_vTree->Cell[insertAt][0]->ImageHAlign = halignSftTreeRight;
    } else if (pDataObject->GetFormat(sftCFFiles)) {
        m_vTree->BulkUpdate = VARIANT_TRUE;

See Also SftTreeItems Object | Object Hierarchy


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