locked
to get the selected value from the combo box in WPF RRS feed

  • Question

  • I try to get the selected value from the combo box in WPf.
    The data from specific table is populated into the combo.
    I already tried with the following code.
    string cmbvalue = "";
    System.Windows.Controls.ComboBoxItem curItem = ((System.Windows.Controls.ComboBoxItem)Cmbfilter.SelectedItem);
    ID = curItem.Content;

    but error occurs when I implemented this code. The error is Cmbfilter is not in the current context.

    how to slove this problem?


    thanks in advance.
    Htar Su
    Monday, July 13, 2009 3:23 AM

Answers

  • Hi,

    if the error is CmbFilter is not in the current context, it means that you probably misspelled the name of the combobox, or it is out of scope at the point where you use this code.

    Second, the type of SelectedItem is probably not ComboBoxItem, but the item/record type of the underlaying table, which you assigned to ItemsSource.
    • Proposed as answer by Hua Chen Monday, July 20, 2009 3:59 AM
    • Marked as answer by Hua Chen Friday, July 31, 2009 10:44 AM
    Monday, July 13, 2009 6:57 AM

All replies

  • hi
    try
    string cmbvalue = Cmbfilter.SelectedValue.ToString();

    hope it wil solve your problem
    Harshad..... Always 4 U
    Monday, July 13, 2009 6:35 AM
  • Hi,

    if the error is CmbFilter is not in the current context, it means that you probably misspelled the name of the combobox, or it is out of scope at the point where you use this code.

    Second, the type of SelectedItem is probably not ComboBoxItem, but the item/record type of the underlaying table, which you assigned to ItemsSource.
    • Proposed as answer by Hua Chen Monday, July 20, 2009 3:59 AM
    • Marked as answer by Hua Chen Friday, July 31, 2009 10:44 AM
    Monday, July 13, 2009 6:57 AM