This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.
-
Comments
- MattK on The joys of a bilingual office
- Alex P on The joys of a bilingual office
- Georgia on Somebody get that monster a cookie
- The country and the country on Books: The City and the City by China Mieville
- Emmet Brown und Bullshit-Science-Journalismus | Kontextschmiede on Satoshi Kanazawa cannot think.
Linkies.- Wu Tang vs The BeatlesAaaaaaaaan DOWNLOAD!Enter The Magical Mystery Chambers: Wu Tang acapellas over beats made with samples of Beatles songs. Produced by Tom Caruana. (via Brian Lam) […]
- RCA Airnergy Charges Gadgets with Nothing But Wifi Signals [Chargers]GizmodoIf this works, it is brilliant. First plausible use case for wireless charging.Shared by darrick Mmm, wireless electricity is so sexy! Forget PowerMats and wireless charging and the like, because the Airnergy wi-fi signal harvester is my new front runner for the future of gadget charging. It's not exactly new tech, as ohGizmo notes, but it's the fi […]
- Crash StateGeoff makes my brain bigger.The L.A. Times reports that, "Over the next six months, a budget-induced employee retirement program will shrink [L.A.'s] civilian workforce—a group that excludes the Department of Water and Power—by at least 9%. Some policymakers have only begun grasping the magnitude of the exodus of librarians, building inspectors, tr […]
- Wu Tang vs The Beatles
Books
Databind a ComboBox to an Enum and your business object
Databinding intelligently in .net is usually pretty easy. Recently I wanted to quickly bind a combobox where the items are the values of an enum made up of single words and the selected value is tied to my data object. I was surprised that it wasn’t all that straighforward. Here’s me saving you some time in the future.
What you want is an easy way to get a list of objects that you can bind the combobox to. Here is a list you can easily create from any enum that will give you a handle on the names and values of the enum.
code:
(Enum.GetName(typeof(V),value), (V) value));
public class ComboEnumList <V> : List < keyvaluepair < string,V> >
where V: struct //at least we can constrain that it ain't a class
{
public ComboEnumList():base()
{
//because generics don't allow a constraint like "where V: enum"
if (!typeof(V).IsEnum) throw new Exception( "New Argument Not An Enum " + (typeof(V).FullName));
Array values = Enum.GetValues(typeof(V));
foreach (object value in values)
{
this.Add(new KeyValuePair
}
}
}
To use this, you’d inherit an instance of this class with type V = your enum.
code:
public class AvailableJerseyStyles : ComboEnumList
{}
public enum JerseyStyleEnum{
Stripes,
Diamonds,
Paisley,
CheckerBoard,
Houndstooth
}
Now go into the VS2k5 designer, add a new project data source based on your AvailableJerseyStylesClass. On instantiation, create the AvailableJerseyStyles object and set it as the datasource for your bindingsource. DisplayMemeber = “Key”, ValueMember = “Value”.
Bind the enum property of your business object datasource to the SelectedValue of the AvailableJerseyStylesClass and you are good to go.
Hope it helps.