C# – Auto-populate a dropdown with enum values

When you need to show enum values in a dropdown, it’s a good idea to automatically populate the list, instead of manually setting all of the values. To autopopulate the dropdown, set the DataSource to Enum.Values(), like this: Then to get the option the user picked, do the following: When I launch my form, I … Read more C# – Auto-populate a dropdown with enum values

ArgumentOutOfRangeException: 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 is empty. Solution Are you expecting there to always be data? If you’re expecting there to always be data, … Read more ArgumentOutOfRangeException: InvalidArgument=Value of 0 is not valid for SelectedIndex