Get selected value from combo box in C# WPF

后端 未结 21 604
粉色の甜心
粉色の甜心 2020-12-08 09:29

I have just started using WPF forms instead of Windows Forms forms. In a Windows Forms form I could just do:

ComboBox.SelectedValue.toString();
相关标签:
21条回答
  • 2020-12-08 09:49

    Actually you can do it the following way as well.

    Suppose your ComboBox name is comboBoxA. Then its value can be gotten as:

    string combo = comboBoxA.SelectedValue.ToString();
    

    I think it's now supported since your question is five years old.

    0 讨论(0)
  • 2020-12-08 09:50
    MsgBox(cmbCut.SelectedValue().ToString())
    
    0 讨论(0)
  • 2020-12-08 09:50

    Write it like this:

    String CmbTitle = (cmb.SelectedItem as ComboBoxItem).Content.ToString()
    
    0 讨论(0)
  • 2020-12-08 09:51

    How about these:

    string yourstringname = (yourComboBox.SelectedItem as ComboBoxItem).Content.ToString();
    
    0 讨论(0)
  • 2020-12-08 09:55

    To get the value of the ComboBox's selected index in C# use:

    Combobox.SelectedValue
    
    0 讨论(0)
  • 2020-12-08 09:56

    It's the same principle.

    You can either use SelectedIndex and use ComboBox.Items[SelectedIndex].ToString(). Or just ComboBox.SelectedItem and cast it to any type you need :)

    0 讨论(0)
提交回复
热议问题