event SelectionChanged ()

Fired after a new item has been selected.

 TypeDescription 

The Selection changed event notifies your application that a new item is selected. Use the SelectedItem property to determine the handle of the selected item. Use the Select property to determine the selected value on a specific column. Use the Value property to specify the selected value on a single column control. Use the SelectItem property to select an item given its handle. The Change event is fired if the drop-down portion of the control is visible, and the user clicks an item or presses the Enter key. The SelectableItem property specifies whether the user can select an item. The SearchColumnIndex property indicates the index of the column that has the focus. The AssignEditImageOnSelect property specifies whether the control displays the cell's icon when selection is changed. The AssignEditImageOnSelect property has effect if the Style property is DropDown. The Click event is fired, if the user selects a new item, and the FireClickOnSelect property is True. 

The following samples show options to get the selected item when the user changes the selected item: 

The following VB sample displays the selected item, using the Select property:

Private Sub ComboBox1_SelectionChanged()
    With ComboBox1
        Debug.Print .Select(.SearchColumnIndex)
    End With
End Sub

The following VB sample displays the selected item, using the Items.SelectedItem property:

Private Sub ComboBox1_SelectionChanged()
    With ComboBox1.Items
        Dim h As HITEM
        h = .SelectedItem()
        If (Not h = 0) Then
            Debug.Print .CellCaption(h, 0)
        End If
    End With
End Sub

The following C++ sample displays the selected item, using the Select property:

void OnSelectionChangedCombobox1() 
{
	OutputDebugString( m_combobox.GetEditText( COleVariant(m_combobox.GetSearchColumnIndex() ) ) );
}

The following C++ sample displays the selected item, using the Items.SelectedItem property:

void OnSelectionChangedCombobox1() 
{
	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 Select property:

Private Sub AxComboBox1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AxComboBox1.SelectionChanged
    With AxComboBox1
        Debug.WriteLine(.get_Select(.SearchColumnIndex))
    End With
End Sub

The following VB.NET sample displays the selected item, using the Items.SelectedItem property:

Private Sub AxComboBox1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AxComboBox1.SelectionChanged
    With AxComboBox1.Items
        Dim h As Integer = .SelectedItem()
        If (Not h = 0) Then
            Debug.WriteLine(.CellCaption(h, 0))
        End If
    End With
End Sub

The following C# sample displays the selected item, using the Select property:

private void axComboBox1_SelectionChanged(object sender, EventArgs e)
{
	System.Diagnostics.Debug.WriteLine(axComboBox1.get_Select(axComboBox1.SearchColumnIndex));
}

The following C# sample displays the selected item, using the Items.SelectedItem property:

private void axComboBox1_SelectionChanged(object sender, EventArgs e)
{
	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 Select property:

*** ActiveX Control Event ***

With thisform.ComboBox1
	wait window nowait .Object.Select(.SearchColumnIndex())
EndWith

The following VFP sample displays the selected item, using the Items.SelectedItem property:

*** ActiveX Control Event ***

With thisform.ComboBox1.Items
	.DefaultItem = .SelectedItem(0)
	If (.DefaultItem <> 0) Then
		wait window nowait .CellCaption(0, 0)
	EndIf
EndWith

 



Send comments on this topic.
© 1999-2006 Exontrol Inc, Software. All rights reserved.