Thursday, July 16, 2009

Tip: How to hide datagrid column in Windows Mobile 6.1

Scenario:
I have a datagrid that contains 3 columns; Product Code, Product Package, and Quantity. However, the datasource of the datagrid is a datatable with the name "ProductList" that contains Product Id, Product Code, Product Description, Package, and Qty. When the datatable is binded to the datagrid, all the fields in the datatable are shwon in the datagrid. So how do we hide those unwanted fields from showing in the front end?

Solution:
1. Create a DataGridTableStyle for the DataGrid and add in the styles for column: Product Code, Product Package, and Quantity.
2. In the DataGridTableStyle "MappingName" property, makes sure you put in "ProductList" as the value. This value tells the DataGrid to map the fields to the "ProductList" table and to hide those fields that are not stated in the GridColumnStyles collection.

No comments: