Datagrid Binding to an Object
-
I'm really struggling trying to bind a Datagrid to a collection of objects. I understand that for each public property of the objects in the collection, a column will be displayed. But I don't want to display a column for all of the public properties, just some of them. And I also want to add columns to the datagrid for things like an image that is associated with one of the properties. How do you hide columns when binding to objects? How do you add columns to a datagrid when it is bound to a collection of objects? Any help would be greatly appreciated! Thanks Warwick "I hear they've even got the internet on Computers now." - Homer Simpson
-
I'm really struggling trying to bind a Datagrid to a collection of objects. I understand that for each public property of the objects in the collection, a column will be displayed. But I don't want to display a column for all of the public properties, just some of them. And I also want to add columns to the datagrid for things like an image that is associated with one of the properties. How do you hide columns when binding to objects? How do you add columns to a datagrid when it is bound to a collection of objects? Any help would be greatly appreciated! Thanks Warwick "I hear they've even got the internet on Computers now." - Homer Simpson
If you databind a datagrid to a list of objects, it will create a column for each property as you said. However, if you first create a
DataGridTableStyle
and add to it theDataGridColumnStyle
objects that you want then only those columns will be shown. This can be done directly in the designer. -
If you databind a datagrid to a list of objects, it will create a column for each property as you said. However, if you first create a
DataGridTableStyle
and add to it theDataGridColumnStyle
objects that you want then only those columns will be shown. This can be done directly in the designer. -
I'm really struggling trying to bind a Datagrid to a collection of objects. I understand that for each public property of the objects in the collection, a column will be displayed. But I don't want to display a column for all of the public properties, just some of them. And I also want to add columns to the datagrid for things like an image that is associated with one of the properties. How do you hide columns when binding to objects? How do you add columns to a datagrid when it is bound to a collection of objects? Any help would be greatly appreciated! Thanks Warwick "I hear they've even got the internet on Computers now." - Homer Simpson
Take a look at ITypedList. Adding it to your collection allows you to create property descriptors. The Datagrid will respect this list. This is more "class friendly" to implementers and they won't have to use table styles to get rid of the unfriendly stuff.