property Items.SelectCount as Long

Counts the number of items that are selected into control.

 TypeDescription 
   Long A long expression that identifies the number of selected items.  

The SelectCount property counts the selected items in the control. The SelectCount property gets 0, if no items are selected in the control. The ExTree control supports multiple selection. Use the SingleSel property of the control to allow multiple selection. Use the SelectedItem property to retrieve the handle of the selected item(s). The control fires the SelectionChanged  event when user changes the selection in the control. Use the SelectItem property to select programmatically an item. Use the SelForeColor and SelBackColor properties to specify colors for selected items. If the control supports only single selection ( SingleSel property is True ), the FocusItem retrieves the selected item too. Use the SelectAll method to select all visible items in the tree. Use the UnselectAll method to unselect all items in the control.

If the control's SingleSel is false, then the following statement retrieves the handle for the selected item: Tree1.Items.SelectedItem(). 

If the control supports multiple selection then the following VB sample shows how to enumerate all selected items:

Dim h As HITEM
Dim i As Long, j As Long, nCols As Long, nSels As Long
nCols = Tree1.Columns.Count
With Tree1.Items
    nSels = .SelectCount
    For i = 0 To nSels - 1
        Dim s As String
        For j = 0 To nCols - 1
            s = s + .CellCaption(.SelectedItem(i), j) + Chr(9)
        Next
        Debug.Print s
    Next
End With

The following VB sample unselects all items in the control:

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

The following C++ sample enumerates the selected items:

CItems items = m_tree.GetItems();
long n = items.GetSelectCount();
if ( n != 0 )
{
	for ( long i = 0; i < n; i++ )
	{
		long h = items.GetSelectedItem( i );
		COleVariant vtString;
		vtString.ChangeType( VT_BSTR, &items.GetCellCaption( COleVariant( h ), COleVariant( (long)0 ) ) );
		CString str = V_BSTR( &vtString );
		MessageBox( str );
	}
}

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 enumerates the selected items:

With AxTree1.Items
    Dim nCols As Integer = AxTree1.Columns.Count, i As Integer
    For i = 0 To .SelectCount - 1
        Debug.Print(.CellCaption(.SelectedItem(i), 0))
    Next
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 enumerates the selected items:

for (int i = 0; i < axTree1.Items.SelectCount; i++)
{
	object strCaption = axTree1.Items.get_CellCaption(axTree1.Items.get_SelectedItem(i), 0);
	System.Diagnostics.Debug.WriteLine(strCaption != null ? strCaption.ToString() : "");
}

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 enumerates the selected items:

with thisform.Tree1.Items
	local i
	for i = 0 to .SelectCount - 1
		.DefaultItem = .SelectedItem(i)
		wait window nowait .CellCaption(0,0)
	next
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



Send comments on this topic.
1999-2017 Exontrol.COM, Software. All rights reserved.