Language:

ComboBox mit Werten aus einem Enum füllen

Language: Deutsch
Programming Language: C#
Published by: Olaf [not registered]
Last Update: 5/4/2006
Views: 1192

Description

Befüllt eine ComboBox mit Werten aus einem Enum.

Code

1 // The Enum to use 2 public enum Parity 3 { 4 None = 0, 5 6 Odd = 1, 7 8 Even = 2 9 } 10 11 // Fill the ComboBox with the Enum Values 12 private void FillComboBox() 13 { 14 // Get Array with all Enum Values 15 Parity[] parities = (Parity[])Enum.GetValues(typeof(Parity)); 16 17 // Add Enum Name to ComboBox 18 foreach (Parity parity in parities) 19 { 20 comboBox.Items.Add(parity.ToString()); 21 } 22 23 // Select Default Value 24 comboBox.SelectedItem = Parity.None.ToString(); 25 } 26 27 // Get the selected Enum Value from the Combobox 28 private Parity ReadComboBoxValue() 29 { 30 Parity parity = (Parity)Enum.Parse(typeof(Parity), comboBox.SelectedItem.ToString(), true); 31 32 return parity; 33 } 34

No comments avaiable

Add a comment

Name *  

Email (won't be displayed) *    

Website  

Comment *  

Sicherheitscode Security Code *    

RSS