100 likes | 324 Views
DataGridView Tips and Tricks. Code Camp 2008 Emmet Gray http://home.hot.rr.com/graye. Introduction. DataGridView Provides a GUI for tabular data Look and feel of Excel The DataGridView control New in .Net Framework 2.0 Replaces the older DataGrid control
E N D
DataGridViewTips and Tricks Code Camp 2008 Emmet Gray http://home.hot.rr.com/graye
Introduction • DataGridView • Provides a GUI for tabular data • Look and feel of Excel • The DataGridView control • New in .Net Framework 2.0 • Replaces the older DataGrid control • Windows Form applications only • Not really related to the Web DataGrid control
Gee Wiz Facts • One of the largest controls in the .Net Framework • It’s huge! • Methods: 359 • Properties: 167 • Events: 187
Example • Live demo of “fully automated mode” • New Data Source • Strongly-typed DataSet, TableAdapter • Automatic column generation • Weaknesses of this approach
GUI “Rules of the Game” Design attributes: Intuitive, Responsive Data attributes: Maintain referential integrity Human interface: Ease of use, prevent input errors
Column Types • Out-of-the-box Column Types • DataGridViewTextBoxColumn • DataGridViewCheckBoxColumn • DataGridViewImageColumn • DataGridViewComboBoxColumn • DataGridViewLinkColumn • Only the first 3 column types are automatically generated
Examples • Use of ComboBox column type • Custom column formatting • RowValidating and ErrorProvider control • Global Error checking • Custom Column type
MaskedEditColumn • Custom DataGridViewColumn type uses MaskedEditTextBox control as the base type • It’s always better to prevent user input errors than to detect them
End Notes • The DataGridView control is very versatile • Fully automated mode • Hand tweaking for • Better look and feel • Data Integrity • Error Detection/Error Prevention • Custom column types • Source code is available at: http://home.hot.rr.com/graye/Articles/DataGridView.htm