ComboBox.SelectionChangeCommitted Evento
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Ocorre quando o utilizador altera o item selecionado e essa alteração é exibida no ComboBoxarquivo .
public:
event EventHandler ^ SelectionChangeCommitted;
public event EventHandler SelectionChangeCommitted;
member this.SelectionChangeCommitted : EventHandler
Public Custom Event SelectionChangeCommitted As EventHandler
Tipo de Evento
Exemplos
O exemplo de código seguinte utiliza o SelectionChangeCommitted evento e a SelectionLength propriedade para alterar o comprimento da caixa de texto dependendo do que o utilizador selecionou e comprometeu.
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
Observações
O SelectionChangeCommitted evento é ativado apenas quando o utilizador altera a seleção da caixa combinada, e pode criar um handler para este evento que proporcione um tratamento especial quando ComboBox o utilizador altera o item selecionado na lista. No entanto, dependendo de como está ComboBox configurado e de como o utilizador altera o item selecionado, o SelectionChangeCommitted evento pode não ser ativado. Alternativamente, pode gerir o SelectedIndexChanged, mas note que este evento ocorre quer o índice seja alterado programaticamente ou pelo utilizador.
Para obter mais informações sobre como manipular eventos, consulte Manipulando e gerando eventos.