ComboBox.SelectionChangeCommitted Händelse

Definition

Inträffar när användaren ändrar det markerade objektet och ändringen visas i ComboBox.

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

Händelsetyp

Exempel

I följande kodexempel används SelectionChangeCommitted händelsen och SelectionLength egenskapen för att ändra längden på textrutan beroende på vad användaren har valt och bekräftat.

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

Kommentarer

Händelsen SelectionChangeCommitted utlöses endast när användaren ändrar kombinationsrutans val, och du kan skapa en hanterare för den här händelsen för att tillhandahålla särskild hantering för ComboBox när användaren ändrar det valda objektet i listan. Beroende på hur ComboBox har konfigurerats och hur användaren ändrar det valda objektet SelectionChangeCommitted kan det dock hända att händelsen inte aktiveras. Du kan också hantera SelectedIndexChanged, men observera att den här händelsen inträffar oavsett om indexet ändras programmatiskt eller av användaren.

Mer information om hur du hanterar händelser finns i Hantera och höja händelser.

Gäller för