Fill A ComboBox Using An Enumeration and Retrieve Its Values
Category:C#, VB.NET, ASP.NET
Version Compatibility: Visual Basic.NET
A case may arise where you have to provide a list of possible values in a ComboBox, which can be passed into a function, procedure or a property. For instance, you may want a user to provide the frequency of their mortgage repayments. It would not be a good idea to provide a list of values as 52, 26, 12, 6, and 4 in a ComboBox, which you as a programmer know what it means, but the user may not. It is always a good practice to show options as Weekly, Fortnightly, Monthly, BiMonthly, Quarterly and let your code behind the scenes work out the actual numerical representation for calculation purposes. The sample below shows you how you can achieve this using Enumeration. It saves you the trouble of clocking up the number of lines of code in your application, and is more efficient.
Instructions: Copy the declarations and code below and paste directly into your VB project.