ComboBox.SelectionChangeCommitted Událost

Definice

Nastane, když uživatel změní vybranou položku a tato změna se zobrazí v objektu ComboBox.

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

Event Type

Příklady

Následující příklad kódu používá SelectionChangeCommitted událost a SelectionLength vlastnost ke změně délky textového pole v závislosti na tom, co uživatel vybral a potvrdil.

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

Poznámky

Událost SelectionChangeCommitted je vyvolána pouze tehdy, když uživatel změní výběr pole se seznamem a můžete vytvořit obslužnou rutinu pro tuto událost, která poskytuje zvláštní zpracování pro ComboBox , když uživatel změní vybranou položku v seznamu. V závislosti na tom, jak ComboBox je nakonfigurována a jak uživatel změní vybranou položku, SelectionChangeCommitted však nemusí být událost vyvolána. Alternativně můžete zpracovat SelectedIndexChanged, ale všimněte si, že k této události dochází bez ohledu na to, jestli je index změněn programově nebo uživatelem.

Další informace o zpracování událostí najdete v tématu Zpracování a vyvolávání událostí.

Platí pro