The text of this article is not in this database — only its details are. Read it on the old site: How to Bind an Enum to a ComboBox in C#
2 Comments
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment.
The text of this article is not in this database — only its details are. Read it on the old site: How to Bind an Enum to a ComboBox in C#
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment.
barry lowryPosted Oct 7, 2009, 8:16 AM
I think you can just cast the value for Windows forms. I don't know about WPF but it's all C#. I assume the compiler automatically does what your code does. Here is my sample to fill the combo: // combo formatting for running item actions m_comboBoxAfterRunningItem.DataSource = System.Enum.GetValues(typeof(eTestManagerRunningItemActions)); m_comboBoxAfterRunningItem.FormattingEnabled = true; m_comboBoxAfterRunningItem.Format += delegate(object sender, ListControlConvertEventArgs formatArgs) { formatArgs.Value = Utility.PropertyGridHelpers.EnumDescriptionConverter.GetEnumDescription((Enum)formatArgs.Value); }; // set initial value m_comboBoxAfterRunningItem.SelectedItem = m_TestManager.runningItemAction; // and here is my sample for getting the result m_TestManager.runningItemAction = (eTestManagerRunningItemActions)m_comboBoxAfterRunningItem.SelectedItem;