Geeks With Blogs

Tim Huffam Dotting the I and crossing the T of I.T. April 2010 Entries
Databinding a .Net WinForms ComboBox to an Enum
This is quite simple... Define the enum eg: public enum MyEnum{ ItemOne, ItemTwo, } Within the form set the datasource of the combobox to the values of the enum eg: myCombo.DataSource = System.Enum.GetValues(typeo... To have the combo auto select a value based on a bound object, set the databinding of the combo eg: class MyObject{ private MyEnum myEnumProperty; public MyEnum MyEnumProperty{get {return myEnumProperty;}} } MyObject myObj = new MyObject(); myCombo.DataBindings.Add(new Binding("SelectedIndex", ......

Posted On Wednesday, April 7, 2010 10:00 PM

Copyright © Tim Huffam | Powered by: