Let’s say I have an Order class that has properties such as OrderName, OrderNum , etc…
then to populate a ComboBox with a list of items from this class, let’s say I do it like this:
comboBox1.DisplayMember = "OrderName";
comboBox1.ValueMember = "OrderNum";
comboBox1.DataSource = list.ToArray<Order>();
So here I am hard coding the name of those fields in the code such as “OrderName”. Is there a better way of doing this rather than hard coding the name of the fields? Does it need some sort of dependency injection tricks? What do you suggest?
Below is a modified class I use in several of my ASP.NET applications. The way I’d assign it in your sample is like this:
Class: