Bind Enum to Combobox


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  1. var query = (from int n in Enum.GetValues(typeof(System.Windows.Forms.DialogResult))
  2. select new {
  3. n,
  4. Key = Enum.GetName(typeof(System.Windows.Forms.DialogResult),n)
  5. }
  6. );
  7.  
  8. comboBox1.DataSource = query.ToList();
  9. comboBox1.DisplayMember = "key";
  10. comboBox1.ValueMember = "n";

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.