C# – Fill a dropdown with enum values

When you need to show enum values in a dropdown (ComboBox control with DropDownStyle=DropDown), it’s a good idea to automatically populate the list, instead of manually setting all of the values. To fill the dropdown with the enum’s values, set the DataSource to Enum.Values(), like this: Read more about how to show the enum’s Description … Read more

InvalidArgument=Value of ‘0’ is not valid for ‘SelectedIndex’

Problem Let’s say you’re initializing a ComboBox like this: And you get the following exception: System.ArgumentOutOfRangeException: ‘InvalidArgument=Value of ‘0’ is not valid for ‘SelectedIndex’. (Parameter ‘value’)Actual value was 0.’ You’re getting this exception because the DataSource you’re binding to is empty. Solution Are you expecting there to always be data? If you’re expecting there to … Read more