Retrieves the selected item's handle given its index in selected items collection.


| Type | Description | |||
| Index as Long | Identifies the index of the selected item into selected items collection. | |||
| HITEM | A long expression that indicates the handle of the selected item. |
Currently, The control supports only single selection. Use the SelectCount property to determine whether the control has an item selected. Use the CellCaption property to get the caption of a specified cell. Use the Value property to get the selected value on a single column control. If the control contains multiple columns you can use the Select property to get the selected value on a specified column.
The following VB sample displays the selected item, using the SelectedItem property:
With ComboBox1.Items
Dim h As HITEM
h = .SelectedItem()
If (Not h = 0) Then
Debug.Print .CellCaption(h, 0)
End If
End With
The following C++ sample displays the selected item, using the SelectedItem property:
CItems items = m_combobox.GetItems(); long hItem = items.GetSelectedItem( 0 ); if ( hItem != 0 ) OutputDebugString( V2S( &items.GetCellCaption( COleVariant( hItem ), COleVariant( long(0) ) ) ) );
where the V2S function converts a VARIANT value to a string,
static CString V2S( VARIANT* pv, LPCTSTR szDefault = _T("") )
{
if ( pv )
{
if ( pv->vt == VT_ERROR )
return szDefault;
COleVariant vt;
vt.ChangeType( VT_BSTR, pv );
return V_BSTR( &vt );
}
return szDefault;
}
The following VB.NET sample displays the selected item, using the SelectedItem property:
With AxComboBox1.Items
Dim h As Integer = .SelectedItem()
If (Not h = 0) Then
Debug.WriteLine(.CellCaption(h, 0))
End If
End With
The following C# sample displays the selected item, using the SelectedItem property:
EXCOMBOBOXLib.Items items = axComboBox1.Items; int hItem = items.get_SelectedItem(0); if ( hItem != 0 ) System.Diagnostics.Debug.WriteLine(items.get_CellCaption(hItem,0).ToString());
The following VFP sample displays the selected item, using the SelectedItem property:
With thisform.ComboBox1.Items .DefaultItem = .SelectedItem(0) If (.DefaultItem <> 0) Then wait window nowait .CellCaption(0, 0) EndIf EndWith