Counts the number of items that are selected in the control.


| Type | Description | |||
| Long | A long expression that identifies the number of selected items. |
The SelectCount property counts the selected items in the control. The control supports single or multiple selection. Use SingleSel property of the control to enable multiple selection. Use the SelectedItem property to retrieve the handle of the selected item(s). Use the SelBackColor property to indicate the background color for selected items. Use the SelForeColor property to specify the foreground color for selected items. The FocusItem property specifies the handle of the focused item. For instance, if the control supports single selection the FocusItem property retrieves the handle of the selected item too. Use the FullRowSelect property to specify how the user can select the cells or items using the mouse. Use the SelectItem property to programmatically select an item giving its handle. The control fires the SelectionChanged event when user changes the selection in the control. Use the SelectableItem property to specify whether the user can select an item.
The following VB sample enumerates all selected items in the control:
Dim i As Long, j As Long, nCols As Long, nSels As Long
nCols = Grid1.Columns.Count
With Grid1.Items
nSels = .SelectCount
For i = 0 To nSels - 1
Dim s As String
For j = 0 To nCols - 1
s = s + .CellValue(.SelectedItem(i), j) + Chr(9)
Next
Debug.Print s
Next
End With
The following VB sample unselects all items in the control:
With Grid1
.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_grid.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.GetCellValue( COleVariant( h ), COleVariant( (long)0 ) ) );
CString str = V_BSTR( &vtString );
MessageBox( str );
}
}
The following C++ sample unselects all items in the control:
m_grid.BeginUpdate(); CItems items = m_grid.GetItems(); while ( items.GetSelectCount() ) items.SetSelectItem( items.GetSelectedItem( 0 ), FALSE ); m_grid.EndUpdate();
The following VB.NET sample enumerates the selected items:
With AxGrid1.Items
Dim nCols As Integer = AxGrid1.Columns.Count, i As Integer
For i = 0 To .SelectCount - 1
Debug.Print(.CellValue(.SelectedItem(i), 0))
Next
End With
The following VB.NET sample unselects all items in the control:
With AxGrid1
.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 < axGrid1.Items.SelectCount; i++)
{
object strCaption = axGrid1.Items.get_CellValue(axGrid1.Items.get_SelectedItem(i), 0);
System.Diagnostics.Debug.WriteLine(strCaption != null ? strCaption.ToString() : "");
}
The following C# sample unselects all items in the control:
axGrid1.BeginUpdate(); EXGRIDLib.Items items = axGrid1.Items; while (items.SelectCount != 0) items.set_SelectItem(items.get_SelectedItem(0), false); axGrid1.EndUpdate();
The following VFP sample enumerates the selected items:
with thisform.Grid1.Items local i for i = 0 to .SelectCount - 1 .DefaultItem = .SelectedItem(i) wait window nowait .CellValue(0,0) next endwith
The following VFP sample unselects all items in the control:
With thisform.Grid1 .BeginUpdate() with .Items do while ( .SelectCount() # 0 ) .DefaultItem = .SelectedItem(0) .SelectItem(0) = .f. enddo endwith .EndUpdate() EndWith