Displaying list of objects as single column in a bound gridview (Winforms)?
I have a gridview that is bound to a datasource on a Windows Form (VB.NET). The grid displays a list of "certifications", and each "certification" can be associated with many languages. So in the grid, I'd like to display "languages" as a column, and display a comma delimited list of the language names for each "certification".
In the "certification" class, one of the properties is a list of "language" objects, and each "language" has an ID (guid), name (string), and value (integer).
So in the datasource, I have the list of "languages", but I can't figure out how to display them in a column on the grid. The gridview won't let me add the language list property as a column.
So is the ONLY way to add a new property on the "certification" class, which returns a string that contains the comma delimited list, and show THAT on the grid? Or is there a way to display that list of "开发者_StackOverflow社区languages"?
This is not the only way, but IMHO, this is the most appropriate way. If there is some intelligent composition of data within the class (combining elements of the list into a string) that should be handled internally by the class and properties are the appropriate model. This would be similar to overriding ToString()
for your object. Add to that how nicely databinding works with properties and you have a straight-forward maintainable solution.
精彩评论