// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections; using System.Drawing; using System.Windows.Forms; using System.Xml; public class MainForm : Form { private ComboBox cbx; public MainForm() { try { InitializeComponent(); } catch(Exception ex) { MessageBox.Show(ex.Message); } } public static void Main(string[] args) { Application.Run(new MainForm()); } private void InitializeComponent() { cbx = new ComboBox(); SuspendLayout(); cbx.Location = new Point(50, 50); cbx.Size = new Size(100, 25); cbx.Name = "Dynamic Combo Box"; cbx.SelectedIndexChanged += new EventHandler(ChooseHandler); ArrayList list = new ArrayList(); XmlDocument doc = new XmlDocument(); doc.Load("C:\\cbx.xml"); XmlNodeList elements = doc.GetElementsByTagName("comboboxvalue"); foreach(XmlNode element in elements) { list.Add(element.FirstChild.Value); } cbx.DataSource = list; ClientSize = new Size(200, 200); Name = "Main Form"; Text = "Main Form"; Controls.Add(cbx); ResumeLayout(false); } private void ChooseHandler(object o, EventArgs e) { MessageBox.Show("Du valgte " + ((ComboBox)o).SelectedValue); } }