In my Windows Mobile .NET application I have a simple array of object with the data I want to display in my DataGrid. To do this, I simply call:
myDataGrid.DataSource = myArray;
This works, but I have a problem with it: it uses all properties as columns and uses the names of the properties as the column headers. I can't figure out how to customize two things:
Select which subset of properties should be displayed as columns (say I have an ID, Name and Value property, I'd only want to show Name and Value);
Rename the column headers to make more sense (for example if the property is called ID display a column header saying "Number").
Is this possible at all?
As mentioned this is in a Windows Mobile .NET (version 2) application.
You need to set the Datagrid.TableStyles property to customize the layout.
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagrid.tablestyles.aspx
More details on binding to an array of objects here: http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridtablestyle.mappingname(VS.71).aspx
To bind the System.Windows.Forms.DataGrid to a strongly typed array of objects, the object must contain public properties. To create a DataGridTableStyle that displays such an array, set the MappingName property to classname[] where classname is replaced by the class name. Also note that the MappingName property is case-sensitive.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With