Those are just properties of the Order
, right? So you could use const
- and that would be much better than literals in the code - but you can certainly change them at run time if you wish. You just need to know what they are.
In your class "OrderName" and "OrderNum" are just strings which represent the names of the properties, so if you happened to have other properties in your Order
class, you could get the names of those properties and assign them, say, from some user action.
If you wanted to, you could use reflection to examine the Order
class. Something like:
Type theType =(typeof(Order));
// Get the public properties.
PropertyInfo[] thePropertyInfo =
theType.GetProperties(BindingFlags.Public|BindingFlags.Instance);
To get the name of any particular property in that PropertyInfo array you could something like:
thePropertyInfo[i].Name;
would give you the name of the ith property in the object.
So, you could then, say, put those properties into some list that is, itself bound to a control - like a ComboBox
and then pick at run time what DisplayMember
and ValueMember
would be used, then just set those and the binding will automatically update.