ComboBox.SelectionChangeCommitted Evento

Definición

Se produce cuando el usuario cambia el elemento seleccionado y se muestra dicho cambio en ComboBox.

public:
 event EventHandler ^ SelectionChangeCommitted;
public event EventHandler SelectionChangeCommitted;
public event EventHandler? SelectionChangeCommitted;
member this.SelectionChangeCommitted : EventHandler 
Public Custom Event SelectionChangeCommitted As EventHandler 

Tipo de evento

Ejemplos

En el ejemplo de código siguiente se usa el SelectionChangeCommitted evento y la SelectionLength propiedad para cambiar la longitud del cuadro de texto en función de lo que el usuario haya seleccionado y confirmado.

void comboBox1_SelectionChangeCommitted( Object^ sender, EventArgs^ /*e*/ )
{
   ComboBox^ senderComboBox = dynamic_cast<ComboBox^>(sender);
   
   // Change the length of the text box depending on what the user has 
   // selected and committed using the SelectionLength property.
   if ( senderComboBox->SelectionLength > 0 )
   {
       textbox1->Width = 
           senderComboBox->SelectedItem->ToString()->Length * 
           ((int)this->textbox1->Font->SizeInPoints);
       textbox1->Text = senderComboBox->SelectedItem->ToString();				
   }
}
private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e)
{

    ComboBox senderComboBox = (ComboBox) sender;
  
    // Change the length of the text box depending on what the user has 
    // selected and committed using the SelectionLength property.
    if (senderComboBox.SelectionLength > 0)
    {
        textbox1.Width = 
            senderComboBox.SelectedItem.ToString().Length *
            ((int) this.textbox1.Font.SizeInPoints);
        textbox1.Text = senderComboBox.SelectedItem.ToString();
    }
}
Private Sub comboBox1_SelectionChangeCommitted(ByVal sender _
As Object, ByVal e As EventArgs) _
Handles comboBox1.SelectionChangeCommitted

    Dim senderComboBox As ComboBox = CType(sender, ComboBox)

    ' Change the length of the text box depending on what the user has 
    ' selected and committed using the SelectionLength property.
    If (senderComboBox.SelectionLength > 0) Then
        textbox1.Width = _
            senderComboBox.SelectedItem.ToString().Length() * _
            CType(Me.textbox1.Font.SizeInPoints, Integer)
        textbox1.Text = senderComboBox.SelectedItem.ToString()
    End If
End Sub

Comentarios

El SelectionChangeCommitted evento solo se genera cuando el usuario cambia la selección del cuadro combinado y puede crear un controlador para este evento para proporcionar un control especial para ComboBox cuando el usuario cambia el elemento seleccionado en la lista. Sin embargo, dependiendo de cómo ComboBox se configure y cómo cambia el usuario el elemento seleccionado, es posible que no se genere el SelectionChangeCommitted evento. Como alternativa, puede controlar , SelectedIndexChangedpero tenga en cuenta que este evento se produce si el índice cambia mediante programación o por el usuario.

Para obtener más información sobre el manejo de eventos, consulte controlar y provocar eventos.

Se aplica a