Thursday, November 28, 2013

DataGridViewComboBoxColumn cell value returning null

If productNames is just a List<string> then you don't need to set the ValueMember and DisplayMember. The combo box will implicitly call ToString() on the items if you do not supply them.


The ValueMember and DisplayMember are used when you are binding to objects with properties and you need to specify which property should be shown and which should be the value. For instance, if you had a collection of Person objects the Display member might be "FullName" and the value member might be "PersonId".


When you are setting the value member to productNames.ToString() you are telling it to use the System.Collections.Generic.List[System.String] property of productNames. Of course, productNames has no such property.




Bob - www.crowcoder.com


No comments:

Post a Comment