Open a Windows Forms
Application in Visual studio 2008, named it Enum2Combo
Then,
Sample
Program
using System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Windows.Forms;
namespace Enum2Combo
{
public partial class Form1 : Form
{
enum Metrocities
{
Chennai,
Mumbai,
NewDelhi,
Kolkatta,
}
public
Form1()
{
InitializeComponent();
}
//Double Click On Load Button in Design
//Double Click On Load Button in Design
private
void button1_Click(object
sender, EventArgs e)
{
Array
arr;
arr = Enum.GetValues(typeof(Metrocities));
comboBox1.Items.Clear();
foreach
(Metrocities m in
arr)
{
comboBox1.Items.Add(m);
}
}
}
}
Here, comboBox1.Items.Clear(); used to
avoid multiple insert.. That is Enum Values inserted only once in combobox…
Output:
Before Button Load Click
After Button Load Click
No comments:
Post a Comment