code_junkie

Get the combobox text in C#

Nov 12th, 2011
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. public BookType type
  2. {
  3. get
  4. {
  5. return (BookType)Enum.Parse(typeof(BookType), this.typeComboBox.Text);
  6. }
  7. set
  8. {
  9. this.typeComboBox.Text = value.ToString();
  10. }
  11. }
  12.  
  13. public enum Test
  14. {
  15. One, Two, Three
  16. }
  17.  
  18. public partial class Form1 : Form
  19. {
  20. public Form1()
  21. {
  22. InitializeComponent();
  23.  
  24. this.comboBox1.DataSource = Enum.GetNames(typeof(Test));
  25. }
  26.  
  27. public Test Test
  28. {
  29. get
  30. {
  31. return (Test)Enum.Parse(typeof(Test), this.comboBox1.Text);
  32. }
  33. set
  34. {
  35. this.comboBox1.Text = value.ToString();
  36. }
  37. }
  38.  
  39. private void button1_Click(object sender, EventArgs e)
  40. {
  41. MessageBox.Show(this.Test.ToString());
  42.  
  43. this.Test = Test.Two;
  44.  
  45. MessageBox.Show(this.Test.ToString());
  46. }
  47. }
  48.  
  49. string selectedText = this.ComboBox.GetItemText(this.ComboBox.SelectedItem);
Add Comment
Please, Sign In to add comment