Get selected value from combo box in C# WPF

后端 未结 21 676
粉色の甜心
粉色の甜心 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 10:12

    if you want to get the value and validate it you can do something like this

    string index = ComboBoxDB.Text;
            if (index.Equals(""))
            {                
                MessageBox.Show("your message");
            }
            else
            {
                openFileDialog1.ShowDialog();
                string file = openFileDialog1.FileName;
                reader = new StreamReader(File.OpenRead(file));
            }
    

提交回复
热议问题