Getting the new value of the text in a Combobox [C#]

Shaitan00

Junior Contributor
Joined
Aug 11, 2003
Messages
358
Location
Hell
Something really odd - when the user changes the text in a combobox [cbClient] it launches the cbClient_TextChanged event at which point I want to evaluate the NEW value in cbClient to see if it matches a certain criteria.
Problem I am having (no clue why) is that when the event is handled the value of "CbClient.text" is still the OLD value and not the new updated value.

For example - currently in cbClient.Text = "Client1", if there user deletes/backspaces the "1" then the NEW value in cbClient should be = "Client" HOWEVER when (in the event) I do cbClient.Text it still gives me the OLD value "Client1".
Is there anyway to get the NEW value? Use a different event? Different command? Thanks...
 
Strange. I get the behavior you mentioned when the control is bound to a datasource, but not when I populate the Items collection manually:

Code:
private void comboBox1_TextChanged(object sender, System.EventArgs e)
{
    MessageBox.Show(this.comboBox1.Text);
}

private void Form1_Load(object sender, System.EventArgs e)
{
    this.comboBox1.Items.AddRange(new string[] {"Item 1","Item 2","Item 3","Item 4"});
}
 
Back
Top