Thanks for the info!
@Adam: Thanks; you beat me by 7 seconds.
SLaks
2010-04-25 22:17:00
Oh how nice! Such useful things in .NET!
Serg
2010-04-25 22:18:46
8 minute wait time
Serg
2010-04-25 23:44:09
A:
Here's some code we used on a recent project. It handles localized Enum strings (by passing in a ResourceManager
object) and populates the .Items
array directly instead of using a DataSource -- this is useful for populating a ComboBox
, including setting its .SelectedItem
, before making it or its parent controls visible.
public static void PopulateComboBox<T>(ComboBox box, ResourceManager res) {
box.FormattingEnabled = true;
ListControlConvertEventHandler del = delegate(object sender, ListControlConvertEventArgs e) {
e.Value = res.GetString(e.Value.ToString());
};
box.Format -= del;
box.Format += del;
box.BeginUpdate();
box.Items.Clear();
foreach(T value in Enum.GetValues(typeof(T))) {
box.Items.Add(value);
}
box.EndUpdate();
}
Use it like:
PopulateComboBox<MyEnum>(myComboBox, MyEnumStrings.ResourceManager);
Daniel Pryden
2010-04-25 22:32:12