Type | Description | |||
Value as Variant | A long expression that indicates the value of the item being searched, a string expression that indicates the caption of the item being searched. | |||
Variant | A string expression that indicates the caption of the item, if the Value is a long expression, a long expression that indicates the item's value if Value is a string expression. |
The following VB sample prints the caption of the item with the value 6:
With Record1 .BeginUpdate With .Add("DropDownList", EXRECORDLibCtl.DropDownListType) .DropDownAutoWidth = False .AddItem 0, "Root 1" .InsertItem 1, "Child 1", , 0 .InsertItem 2, "Child 2", , 0 .InsertItem 3, "SubChild 2.1", , 2 .InsertItem 4, "SubChild 2.2", , 2 .AddItem 5, "Root 2" .InsertItem 6, "Child 1", , 5 .InsertItem 7, "Child 2", , 5 .InsertItem 8, "SubChild 2.1", , 6 .InsertItem 9, "SubChild 2.2", , 6 Debug.Print .FindItem(6) End With .EndUpdate End With
The sample displays the "Child 1" string that's the caption for the item with the value 6.
The following VB sample displays the value of the item with the caption "SubChild 2.1":
With Record1 .BeginUpdate With .Add("DropDownList", EXRECORDLibCtl.DropDownListType) .DropDownAutoWidth = False .AddItem 0, "Root 1" .InsertItem 1, "Child 1", , 0 .InsertItem 2, "Child 2", , 0 .InsertItem 3, "SubChild 2.1", , 2 .InsertItem 4, "SubChild 2.2", , 2 .AddItem 5, "Root 2" .InsertItem 6, "Child 1", , 5 .InsertItem 7, "Child 2", , 5 .InsertItem 8, "SubChild 2.1", , 6 .InsertItem 9, "SubChild 2.2", , 6 Debug.Print .FindItem("SubChild 2.1") End With .EndUpdate End With
The sample displays 3 as being the value of the "SubChild 2.1" item.
The following VC sample looks for the item with the value 6:
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; }
COleVariant vtMissing; vtMissing.vt = VT_ERROR; CEditor editor = m_record.Add(COleVariant("DropDownList"), /*DropDownListType*/ 3, vtMissing ); editor.SetDropDownAutoWidth( FALSE ); editor.AddItem( 0, "Root 1", vtMissing ); editor.InsertItem( 1, "Child 1", vtMissing, COleVariant( long(0) ) ); editor.InsertItem( 2, "Child 2", vtMissing, COleVariant( long(0) ) ); editor.InsertItem( 3, "SubChild 2.1", vtMissing, COleVariant( long(2) ) ); editor.InsertItem( 4, "SubChild 2.2", vtMissing, COleVariant( long(2) ) ); editor.AddItem( 5, "Root 2", vtMissing ); editor.InsertItem( 6, "Child 1", vtMissing, COleVariant( long(0) ) ); editor.InsertItem( 7, "Child 2", vtMissing, COleVariant( long(0) ) ); editor.InsertItem( 8, "SubChild 1.1", vtMissing, COleVariant( long(6) ) ); editor.InsertItem( 9, "SubChild 1.2", vtMissing, COleVariant( long(6) ) ); COleVariant vtItem = editor.GetFindItem( COleVariant( (long)6 ) ); OutputDebugString( V2S( &vtItem ) );
The sample displays in the output window the "Child 1" string that indicates the caption of the item with the value 6.
The following VC sample looks for an item given its caption:
COleVariant vtMissing; vtMissing.vt = VT_ERROR; CEditor editor = m_record.Add(COleVariant("DropDownList"), /*DropDownListType*/ 3, vtMissing ); editor.SetDropDownAutoWidth( FALSE ); editor.AddItem( 0, "Root 1", vtMissing ); editor.InsertItem( 1, "Child 1", vtMissing, COleVariant( long(0) ) ); editor.InsertItem( 2, "Child 2", vtMissing, COleVariant( long(0) ) ); editor.InsertItem( 3, "SubChild 2.1", vtMissing, COleVariant( long(2) ) ); editor.InsertItem( 4, "SubChild 2.2", vtMissing, COleVariant( long(2) ) ); editor.AddItem( 5, "Root 2", vtMissing ); editor.InsertItem( 6, "Child 1", vtMissing, COleVariant( long(0) ) ); editor.InsertItem( 7, "Child 2", vtMissing, COleVariant( long(0) ) ); editor.InsertItem( 8, "SubChild 1.1", vtMissing, COleVariant( long(6) ) ); editor.InsertItem( 9, "SubChild 1.2", vtMissing, COleVariant( long(6) ) ); COleVariant vtItem = editor.GetFindItem( COleVariant( "SubChild 2.2" ) ); OutputDebugString( V2S( &vtItem ) );
The sample displays in the output window the 4 value that corresponds to the "SubChild 2.2" item.