Saturday, November 3, 2007

Basic usage of DataGridView Control

The DataGridView control is a new control in Windows Forms 2.0 and it replaces the DataGrid control in Windows Forms 1.0. It is a very powerful and versatile control suitable for displaying tabular data from various data sources. Because of its flexibility, using it efficiently sometimes may not be as simple as it looks like.
One of the big advantage of DataGridView is that it can bind to various different data sources including Array, DataTable, and even custom objects.
There is one simple gotcha when using Array as the data source for a datagridview. By default, DataGridView control display the first public property of the object in the array. For example, if a string array is used as data source for a datagridview, only the length of the string object will be displayed, but not the actually string object. To actually display the string, a user defined object can be used to wrap the string as a public property.
I found a very detailed and useful summary at http://windowsclient.net/samples//Go To market/DataGridView/DataGridView FAQ.doc

No comments: