Reputation: 10267
I would like to use the values in an enum as the source for some comboboxes. This compiles, but doesn't populate the combobox:
private enum ValueType { Text, Barcode }
private ValueType vt;
private void FormCPCLCodeGenUtil_Load(object sender, EventArgs e)
{
comboBoxType1.DataSource = vt;
}
...which shouldn't surprise me, as vt hasn't been assigned a value; and I don't want the combobox to just have one value. So how can I do this (or is there a better way than using an enum as the data source)?
A side question: which one of these is better, when several comboboxes will use the same data source :
comboBoxType1.DataSource = Enum.GetNames(typeof(ValueType));
comboBoxFontSize1.DataSource = Enum.GetNames(typeof (FontSizeType));
comboBoxAlign1.DataSource = Enum.GetNames(typeof(AlignOptions));
//comboBoxType2.DataSource = comboBoxType1.DataSource;
comboBoxType2.DataSource = Enum.GetNames(typeof(ValueType));
(using the previously assigned comboboxes data source as its own, or connecting in the same way as the previous one?)
Upvotes: 1
Views: 2773
Reputation: 13579
you can try this
comboBoxType1.DataSource= Enum.GetNames(typeof(ValueType));
Upvotes: 7