datagridview tips and tricks code camp 2008 emmet gray

10
DataGridView DataGridView Tips and Tricks Tips and Tricks Code Camp 2008 Code Camp 2008 Emmet Gray Emmet Gray http://home.hot.rr.com/graye http://home.hot.rr.com/graye

Upload: bernard-short

Post on 03-Jan-2016

228 views

Category:

Documents


4 download

TRANSCRIPT

DataGridViewDataGridViewTips and TricksTips and Tricks

Code Camp 2008Code Camp 2008

Emmet GrayEmmet Grayhttp://home.hot.rr.com/grayehttp://home.hot.rr.com/graye

IntroductionIntroduction

DataGridViewDataGridView Provides a GUI for tabular dataProvides a GUI for tabular data Look and feel of ExcelLook and feel of Excel

The DataGridView controlThe DataGridView control New in .Net Framework 2.0New in .Net Framework 2.0 Replaces the older DataGrid controlReplaces the older DataGrid control Windows Form applications onlyWindows Form applications only Not really related to the Web DataGrid controlNot really related to the Web DataGrid control

ExampleExample

Gee Wiz FactsGee Wiz Facts

One of the largest controls in the .Net One of the largest controls in the .Net FrameworkFramework

It’s huge!It’s huge! Methods: 359Methods: 359 Properties: 167Properties: 167 Events: 187Events: 187

ExampleExample

Live demo of “fully automated mode”Live demo of “fully automated mode” New Data SourceNew Data Source Strongly-typed DataSet, TableAdapterStrongly-typed DataSet, TableAdapter Automatic column generationAutomatic column generation

Weaknesses of this approachWeaknesses of this approach

GUI “Rules of the Game”GUI “Rules of the Game”

Design attributes: Intuitive, ResponsiveDesign attributes: Intuitive, Responsive

Data attributes: Maintain referential Data attributes: Maintain referential integrityintegrity

Human interface: Ease of use, prevent Human interface: Ease of use, prevent input errorsinput errors

Column TypesColumn Types

Out-of-the-box Column TypesOut-of-the-box Column Types DataGridViewTextBoxColumnDataGridViewTextBoxColumn DataGridViewCheckBoxColumnDataGridViewCheckBoxColumn DataGridViewImageColumnDataGridViewImageColumn DataGridViewComboBoxColumnDataGridViewComboBoxColumn DataGridViewLinkColumnDataGridViewLinkColumn

Only the first 3 column types are Only the first 3 column types are automatically generatedautomatically generated

ExamplesExamples

Use of ComboBox column typeUse of ComboBox column typeCustom column formattingCustom column formattingRowValidating and ErrorProvider controlRowValidating and ErrorProvider controlGlobal Error checkingGlobal Error checkingCustom Column typeCustom Column type

MaskedEditColumnMaskedEditColumn

Custom DataGridViewColumn type uses Custom DataGridViewColumn type uses MaskedEditTextBox control as the base MaskedEditTextBox control as the base typetype

It’s always better to It’s always better to preventprevent user input user input errors than to errors than to detectdetect them them

End NotesEnd NotesThe DataGridView control is very versatileThe DataGridView control is very versatile Fully automated modeFully automated mode Hand tweaking forHand tweaking for

Better look and feelBetter look and feelData IntegrityData IntegrityError Detection/Error PreventionError Detection/Error Prevention

Custom column typesCustom column types

Source code is available at:Source code is available at:http://home.hot.rr.com/graye/Articles/DataGridView.htmhttp://home.hot.rr.com/graye/Articles/DataGridView.htm