I have this code

private void FrmNovedadMedidas_SelectionChangeCommitted(object sender, EventArgs e)
        {
            ComboBox c = (ComboBox)sender;
            CargarMedidasPorIdTipoMedida(Convert.ToInt16(c.SelectedValue));
            this.txtBoxNombreTipoMedida.Text = c.SelectedText;
        }

in c.SelectedValue got the new value of the selection (the one that the user has selected in the Combo). But in c.SelectedText I got the old value of the ComboBox (I mean, the one that was before the user change the selection).

Is there any property that can give me the new Selected Text? I want to avoid to search in the DataSet binded to the ComboBox everytime.

I've read this but doesn't work, I don't have CommitEdit() in ComboBox

edit:

c.Text also gives me the old one

有帮助吗?

解决方案

I seem to remember this situation having to do with the DropDownStyle of the ComboBox.

Can you please try different styles and see if the Text property is set to the new value inside SelectionChangeCommited ?

As per your comment, it seems using DropDownList style solves the issue.

Cheers

其他提示

I found something.

c.GetItemText(c.SelectedItem)

Is there a directly properties, post it please. Thanks for readme anyway.

Try the SelectedIndexChanged event on the ComboBox versus the SelectionChangeCommited event. Then use c.Text to get the value the user just selected.

c.SelectedValue() returns null for me.

c.GetItemText(c.SelectedItem) works for me though. Changing the dropdownstyle wasn't an option.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top