Thursday 30 October 2008

Joys of DGV -> DataGrid "Grande Vitesse"

There are multifarious ways to populate a DGV. One way is to create a BindingSource and then set that to be the datasource of your DGV. DGV uses what has been appelle'd the "standard WinForms data binding model".

If you have been using the old DataGrid of yore, you need to familiarise yourself with the diffs between DataGrid and DataGridView. DGV adds features missing from the mere Datagrid, understand bound and unbound data.

What MSDN says about "wor friend" DGV est (SCooBee DOO, DOO = dgv):

DGV is Truly Scalable!!! We can go from SMALL, read-only data views to LARGE EDITABLE views of data.
DGV is Truly Customisable!!! You can programmatically create your own CUSTOM SORTS and create your own types of CELLS. Yahoo! Awesomable customisable grid here we come!
DGV is Truly BINDABLE! (more on this amazing BINDABILITY property later!)

It will bind like a MAGENTRON to objects implementating:

1. Immortal IList interface of System.Collections fame (wa-hoo, that includes one-dimensional arrays! I am so pleased!)
2. AWESOME IListSOURCE interface, of System.ComponentModel fame (for "bindable" lists), implementes IList incidentally, the key question being does it offer any additional beneficiences? no major differences, except naming convention... just seems like this is the wrapper version for WinForm components...DataTable and DataSet implement the IListSource interface.

There are also to other classes capable of binding nicely to the DGV, they both have BINDING in their worth-mentioning names:

1. IBindingList interface.
2. IBindingListView interface.

Key Question - what are the actual physical mechanics of data binding to the DGV?

Most of time, you will create a BindingSource component containing most of the details of connecting to the data source. The BS component can represent any WinForms data source (WA-HOO)!

Make sure binding source for DGV is set programmatically and not via the IDE (you will have problems).

Style-wise, dgv.AutoResizeColumns should be used with caution, especially if you have set "preferred" widths for your columns.

No comments: