I would use Dictionary for this, so there was no parsing. (It works well when there is a fixed choice.) I am more familiar with Delphi UI controls than .NET, so there may be a better way to populate a ComboBox than what I'm doing here, but I'm sure someone will tell me if is, and I can fix it.
(The code is Oxygene, but it should be easily translatable in C # or VB.Net.)
method MainForm.MainForm_Load(sender: System.Object; e: System.EventArgs); var KC: Dictionary<String, Int32>.KeyCollection; begin aItems := new Dictionary<String, Int32>; aItems.Add('15 min', 15); aItems.Add('30 min', 30); aItems.Add('1 hr', 60); aItems.Add('1 hr 30 min', 90); aItems.Add('2 hr', 120); aItems.Add('2 hr 30 min', 150); KC := aItems.Keys; for s in KC do comboBox2.Items.Add(s); comboBox2.DropDownStyle := ComboBoxStyle.DropDownList; end; method MainForm.comboBox2_SelectedIndexChanged(sender: System.Object; e: System.EventArgs); begin
source share