Show yes/no in bool column of gridview bound to datasource in Winforms?
I have a gridview that is bound to a datasource (Windo开发者_如何学Cws Forms, VB.NET). One of columns is a property of type boolean, and I want to show "yes/no" in the column instead of 0/1 or "true/false". Is this possible? Can you edit displays of columns that are bound?
I have encountered the same problem, unfortunately I didn't find an elegant solution. Three workarounds are proposed:
- Add another property to the data source's class, which returns your string representation of the boolean property. Hide the column showing the boolean value, display the column showing the string value.
- Add an unbound string column, populate that column with the appropriate value for each row, and hide the boolean bound column.
- Create a wrapper class for your data class, which exposes the properties as you'd like them to be shown in the datagrid.
精彩评论