I’ve been populating a combobox this way (getRoundingMethodVals() returns a List<String>):
comboBoxRounding.DataSource = RateSetupData.getRoundingMethodVals();
…but I saw on a StackOverflow answer the following:
comboBox1.DataSource = new BindingSource(dict, null);
…which makes me wonder if I should change my code to:
comboBoxRounding.DataSource = new BindingSource(RateSetupData.getRoundingMethodVals(), null);
Is this a six-of-one-and-half-a-dozen-of-the-other situation? Or does one way hold a strong advantage over the other?
Depends on what you want to do. If you just need to populate the comboBox for a user to select a value, then your first way works very well. It’s a one way data flow: from lsit to control. In your case, a simple List(Of String) doesn’t need a binding source.
However, if you have a much more complex object and want a change in the combobox value to also change the value of that object, you would use the BindingSource. This creates a two-way data flow. (For this scenario, you could use a BindingList which implements many of the BindingSource interfaces.)