Code example:
private void comboBox_SelectedIndexChanged(object sender, EventArgs e)
{
if(some condition)
{
comboBox.Text = "new string"
}
}
My problem is that the comboBox text always shows the selected index's string value and not the new string. Is the a way round this?
Perhaps it would help if you could explain exactly what you're trying to do. I find that the SelectionChangeCommitted event is considerably more useful for purposes like what you describe than SelectedIndexChanged. Among other things, it's possible to change the selected index again from SelectionChangeCommitted (e.g. if the user's selection is invalid). Also, changing the index from code fires SelectedIndexChanged again, whereas SelectionChangeCommitted is only fired in response to user actions.
you should use:
//100% worked
You should reset the
SelectedIndex
property to -1 when setting theText
property.I searching for solution for same issue. But solve it by handling Format event:
Move your change code outside of combobox event: