4

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

Community
  • 1
  • 1
Gonzalo.-
  • 12,512
  • 5
  • 50
  • 82
  • 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 ? – Luc Morin Oct 19 '12 at 17:58
  • Using DropDownList solve this, and also solve another problem that I was checking. Thanks so much !! Please post it as an answer So I can accept it – Gonzalo.- Oct 19 '12 at 18:04

4 Answers4

4

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

Gonzalo.-
  • 12,512
  • 5
  • 50
  • 82
Luc Morin
  • 5,302
  • 20
  • 39
2

I found something.

c.GetItemText(c.SelectedItem)

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

Gonzalo.-
  • 12,512
  • 5
  • 50
  • 82
1

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

Gonzalo.-
  • 12,512
  • 5
  • 50
  • 82
  • 1
    The problem is that in that case fire even the programatically selection changes, and I want to avoid that – Gonzalo.- Oct 19 '12 at 18:05
0

c.SelectedValue() returns null for me.

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

nkr
  • 3,026
  • 7
  • 31
  • 39