property Items.SelectItem(Item as HITEM) as Boolean

Selects or unselects a specific item.

TypeDescription
Item as HITEM A long expression that indicates the item's handle that is selected or unselected.
Boolean A boolean expression that indicates the item's state. True if the item is selected, and False if the item is not selected.

Use the SelectItem to select or unselect a specified item (that's selectable). Use the SelectableItem property to specify the user can select an item. Use the SelectCount property to get the number of selected items. Use the SelectedItem property to get the selected item. Use the FocusItem property to get the focused item. If the control supports only single selection, you can use the FocusItem property to get the selected/focused item because they are always the same. The control fires the SelectionChanged event when user selects an item. Use the SelForeColor and SelBackColor properties to specify colors for selected items. Use the SingleSel property to allow multiple selection. Use the SelectPos property to select an item giving its position. Use the EnsureVisibleItem property to ensure that an item is visible. Use the SelectAll method to select all visible items in the tree. Use the UnselectAll method to unselect all items in the control.

The following VB sample shows how to select the first created item: Tree1.Items.SelectItem(Tree1.Items(0)) = True

The following VB sample selects the first visible item:

With Tree1.Items
    .SelectItem(.FirstVisibleItem) = True
End With

The following VB sample enumerates the selected items:

Dim i As Long
With Tree1.Items
    For i = 0 To .SelectCount - 1
        Debug.Print .CellCaption(.SelectedItem(i), 0)
    Next
End With

The following C++ sample selects the first visible item:

#include "Items.h"
CItems items = m_tree.GetItems();
items.SetSelectItem( items.GetFirstVisibleItem(), TRUE );

The following C++ sample unselects all items in the control:

m_tree.BeginUpdate();
CItems items = m_tree.GetItems();
while ( items.GetSelectCount() )
	items.SetSelectItem( items.GetSelectedItem( 0 ), FALSE );
m_tree.EndUpdate();

The following VB.NET sample selects the first visible item:

With AxTree1.Items
    .SelectItem(.FirstVisibleItem) = True
End With

The following VB.NET sample unselects all items in the control:

With AxTree1
    .BeginUpdate()
    With .Items
        While Not .SelectCount = 0
            .SelectItem(.SelectedItem(0)) = False
        End While
    End With
    .EndUpdate()
End With

The following C# sample selects the first visible item:

axTree1.Items.set_SelectItem(axTree1.Items.FirstVisibleItem, true);

The following C# sample unselects all items in the control:

axTree1.BeginUpdate();
EXTREELib.Items items = axTree1.Items;
while (items.SelectCount != 0)
	items.set_SelectItem(items.get_SelectedItem(0), false);
axTree1.EndUpdate();

The following VFP sample selects the first visible item:

with thisform.Tree1.Items
	.DefaultItem = .FirstVisibleItem
	.SelectItem(0) = .t.
endwith

The following VFP sample unselects all items in the control:

With thisform.Tree1
	.BeginUpdate()
	with .Items
		do while ( .SelectCount() # 0 )	
			.DefaultItem = .SelectedItem(0)
			.SelectItem(0) = .f.
		enddo
	endwith
	.EndUpdate()
EndWith