Data binding with Windows Forms 2.0 programming smart client data applications with .NET
β Scribed by Noyes, Brian
- Publisher
- Addison-Wesley Professional
- Year
- 2006
- Tongue
- English
- Leaves
- 735
- Series
- Microsoft .NET development series
- Category
- Library
No coin nor oath required. For personal study only.
β¦ Synopsis
"Brian Noyes' writing style easily captures your attention as he elaborates on all aspects of data binding in his book. He has a refreshingly clear and crisp delivery as he starts each chapter with a simple tour of each topic, and then leads you into practical concerns for sound practices and extensibility opportunities. Most importantly, as Brian explains approaches to data-binding architecture, patterns of usage, the value of data sets, binding controls and the rest, he always describes how he reaches his recommendations on the topic. This book is perfect for newcomers to .NET 2.0, but also for those that have some experience. Anyone who cares about data in their applications (okay, that should be almost everyone) is guaranteed to learn something new and useful by reading Brian's book."
--Michele Leroux Bustamante, IDesign chief architect, Microsoft regional director, and MVP"Brian has saved me a lot of time. I'm writingThe Hitchhiker's Guide to Visual Studio and SQL Server 2005 (7th Edition)and I'm not going to have to cover data binding nearly as deeply because Brian has done it for me. His book gets right to the meat of the subject and makes data binding look easy. I was also pleased to see that the book focuses on the misunderstood and under-applied Windows Forms architecture. It's a must-read for anyone trying to make their application more interactive and to leverage the new Visual Studio 2005 technology. I'm planning to point my readers to this resource when they need an in-depth treatment of data binding."
--William Vaughn, president, Beta V Corporation"Data binding has finally come of age in Windows applications. Back in the Visual Studio 6.0 days, I ignored data binding completely and wrote my own repetitive code to encapsulate my business logic. With Visual Studio 2005, we finally have a robust and compelling data-binding technology. To ignore it today would make you inefficient and put you behind the curve. Brian delivers a clear and concise discussion of a core topic of development for Windows today. A combination of an easy-to-follow conversational yet technical tone, excellent examples, and solid explanations make this a must-read for any developer writing for Windows or learning to write for Windows."
--Stephen Forte, chief technical officer, Corzen Inc."This book provides a clear, readable, and in-depth treatment of data binding, with detailed discussions of best practices in the presentation and use of data. Brian communicates his knowledge on the mechanics of data binding to give the low-level understanding that makes all the difference when building sophisticated applications and troubleshooting difficult problems. Effective data binding can enormously reduce the amount of code in your applications and will allow new levels of sophistication in your development. Read this book."
--Jonathan Cogley, chief executive officer, Thycotic, ASPInsider, and C# MVP"The .NET Framework 2.0, Visual Studio .NET 2005, and Windows Forms 2.0 incorporate the most powerful data-binding platform yet, and absolutely need a book like this to expose it. Brian's extensive data-binding knowledge and experience shine through as he comprehensively explores its many facets, starting with the fundamentals before tackling a wide variety of real-world scenarios. I've always thought a data-binding book was necessary, and I'm glad Brian found the time to write his."
--Michael Weinhardt, freelance author and application developer"Data Binding with Windows Forms 2.0earns a gold star and a prized place in my development book library. Brian is an exceptional teacher of technology, best practices, and technique. He continues to educate at every presentation I attend; his book carries that quality to paper. I found this book to be highly informative and full of all the important steps and examples necessary to learn this technology. In this book, Brian demonstrates a firm grasp on the concepts and I really enjoy his efforts to promote best practices at every chance. Definitively a cover-to-cover read."
--Randy Hayes, president, Expert Network Solutions, Inc."Brian's direct and well-organized presentation makes this much misunderstood topic finally understandable."
--Sahil Malik, author ofPro ADO.NET 2.0and C# MVPData binding is the most important part of many business applications--and one of the most difficult things to understand.Data Binding with Windows Forms 2.0is the first book to focus on this crucial area of development. It will quickly get you up to speed on binding data sources to Windows Forms components. The book contains clear examples in C# that work with SQL Server 2000 and SQL Server 2005. Visual Basic .NET examples are available on the book's Web site.
Brian Noyes, leading consultant and speaker on .NET programming, teaches you both the theory and practice of data binding and provides numerous samples ready to run in Visual Studio 2005.
From his in-depth coverage, you'll learn how to
Use Visual Studio 2005 to generate a data-bound application from a database Use the new Visual Studio 2005 typed data set designer, and how and why to use typed data sets and typed data adapters Perform simple and complex binding of data to controls, and how to use the .NET 2.0 BindingSource Use the Binding object for simple binding with automatic formatting, and how to handle binding events Generate bound controls with the Visual Studio Designer, and how to use Data Sources Present data with the new DataGridView control, and how to implement advanced features of the DataGridView Implement custom data-bound controls in Windows Forms Create custom business objects and collections that are suitable for use in data binding Implement validation and error handling at the Windows Forms and data-binding levels Implement data binding with ASP.NET 2.0 and the upcoming Windows Presentation Foundation (Avalon) technologies
β¦ Table of Contents
Contents......Page 10
Foreword......Page 22
Preface......Page 24
Acknowledgments......Page 36
About the Author......Page 38
1 Building Data-Bound Applications with Windows Forms......Page 40
What Is Data Binding?......Page 41
Your First Data-Bound Windows Forms 2.0 Application......Page 42
Creating a Windows Application Project......Page 43
Adding a New Data Source and a Data Connection......Page 45
Selecting Data Objects......Page 47
Customizing Data Sources Control Mappings......Page 49
Generating Data-Bound Controls......Page 50
Running the Application......Page 52
Data-Binding Landscape......Page 53
Data Sources......Page 54
Data Objects and Collections......Page 55
DataSets or Not, That Is the Question.........Page 57
Data-Bound Controls......Page 59
Layered Application Architecture......Page 60
What Is a Smart Client?......Page 66
Where Are We?......Page 67
A Quick Review of DataSets......Page 70
The Quest for Type Safety......Page 73
Typed Data Set Internals......Page 76
Creating Typed Data Sets......Page 80
Creating Typed Data Sets with the Data Set Designer......Page 81
Creating a Typed Data Set and Setting Up a Data Connection......Page 82
Adding Tables to a Data Set......Page 87
Typed Data Set-Generated Code......Page 88
Introduction to Table Adapters......Page 91
Filling and Updating a Typed Data Set with a Table Adapter......Page 95
Connection Management......Page 97
Adding Transaction Support to a Table Adapter......Page 101
Adding Helper Data Access Methods......Page 105
Basing Table Adapters on Stored Procedures or Views......Page 106
Adding a Custom Query to a Table Adapter......Page 108
Using the Query Builder to Write a SQL Statement......Page 111
Configuring a Table Adapter to Use Stored Procedures......Page 113
Creating Typed Data Sets with Command Line Tools......Page 116
Using Typed Data Sets in Your Code......Page 117
Where Are We?......Page 118
The 40,000-Foot View of Data Binding......Page 120
Data Binding Concepts......Page 121
.NET Framework 2.0 Data Binding Enhancements......Page 123
Binding Data Collections to a Grid......Page 125
Binding Data Collections to Multi-Valued Controls......Page 127
Binding Data to Individual Controls on a Form......Page 129
Data Paths Within Data Sources......Page 131
Synchronizing Data Between Controls......Page 135
Smarter Data Containment......Page 136
Paging Through Data......Page 138
Master-Details Data Binding......Page 143
Updating Data Sources Through Data Binding......Page 145
Where Are We?......Page 147
Getting to Know the BindingSource Component......Page 150
Simple Data Binding with Binding Sources......Page 151
Chaining Binding Sources for Master-Details Data Binding......Page 155
Navigating Data Through a Binding Source......Page 160
Manipulating Data Through a Binding Source......Page 161
Using a Binding Source as a Data Storage Container......Page 163
Filling a Binding Source with a Data Reader......Page 165
Sorting, Searching, and Filtering Presented Data with a Binding Source......Page 167
Monitoring the Data with Events......Page 170
Restricting Changes to the Data......Page 172
Underneath the Covers of Data Binding for Complex Types......Page 173
Binding an Image Column to a PictureBox Control......Page 180
Binding a DateTime Column to a DateTimePicker......Page 181
Binding a DateTime Column to a TextBox......Page 183
Binding a Numeric Column to a TextBox......Page 184
Automatic Formatting and Parsing Summary......Page 186
Going Beyond Built-In Type Conversion with Binding Events......Page 187
Handling the Format Event......Page 193
Handling the Parse Event......Page 195
Completing the Editing Process......Page 196
Making the Userβs Life Easier with AutoComplete......Page 199
Data Binding Lifecycle......Page 201
Smarter Child-Parent Data Binding......Page 202
Binding to Multiple Copies of Data......Page 204
Updating Parent Data-Bound Controls from Child Data-Bound Controls......Page 207
Synchronizing Many-to-Many Related Collections......Page 211
Where Are We?......Page 215
Working with the Data Sources Window......Page 216
Adding Data Sources to a Project......Page 218
Choosing the Type of Data Source......Page 219
Adding a Database Data Source......Page 220
Adding a Web Service Data Source......Page 224
Adding an Object Data Source......Page 225
Generating Bound Controls from Data Sources......Page 228
Customizing the Bound Control Types......Page 235
Binding Existing Controls to Data Sources......Page 238
Behind the Scenes: Designer Code and Data Sources Files......Page 241
Other Designer Data-Binding Code Generation......Page 244
Setting Control Data Binding Through the Properties Window......Page 245
Generating Data Bindings with Smart Tags......Page 249
Generating Master-Details Data-Bound Controls with the Designer......Page 253
Where Are We?......Page 255
6 Presenting Data with the DataGridView Control......Page 256
DataGridView Overview......Page 257
Basic Data Binding with the DataGridView......Page 258
Controlling Modifications to Data in the Grid......Page 260
Programmatically Adding Columns to a Grid......Page 261
Programmatically Adding Rows to a Grid......Page 263
Custom Column Content with Unbound Columns......Page 265
Displaying Computed Data in Virtual Mode......Page 272
Setting Up Virtual Mode......Page 273
Initializing the Grid......Page 277
Understanding Virtual Mode Behavior......Page 278
Virtual Mode Summary......Page 279
Using the Built-In Column Types......Page 280
DataGridViewTextBoxColumn......Page 288
DataGridViewLinkColumn......Page 289
DataGridViewImageColumn......Page 290
DataGridViewComboBoxColumn......Page 291
Built-In Header Cells......Page 294
Handling Grid Data Edits......Page 295
Automatic Column Sizing......Page 298
Column and Row Freezing......Page 301
Using the Designer to Define Grids......Page 302
Column Reordering......Page 305
Defining Custom Column and Cell Types......Page 308
Defining a Custom Cell Type......Page 309
Defining a Custom Column Type......Page 312
Utilizing Cell-Oriented Grid Features......Page 316
Formatting with Styles......Page 320
Where Are We?......Page 323
7 Understanding Data-Binding Interfaces......Page 324
What Does Data Binding Have to Do with Interfaces?......Page 325
The IEnumerable and IEnumerator Interfaces: Supporting Iteration Through Collections......Page 328
The ICollection Interface: Controlling Access to a Collection......Page 334
The IList Interface: Enabling Data Binding......Page 337
The IListSource Interface: Exposing Collections of Collections......Page 342
Property Descriptors: Allowing Dynamic Data Item Information Discovery......Page 344
The ITypedList Interface: Exposing Data-Binding Properties......Page 346
Getting to Know the IBindingList Members......Page 349
Notifying Consumers of Changes to the Collection......Page 352
Exercising IBindingList Change Notifications......Page 355
Supporting Sorting with IBindingList......Page 356
Supporting Searching with IBindingList......Page 361
The IBindingListView Interface: Supporting Advanced Sorting and Filtering......Page 362
The ICancelAddNew Interface: Supporting Transactional Inserts in a Collection......Page 364
The IRaiseItemChangedEvents Interface: Providing Item Modification Notifications on Collections......Page 366
The IEditableObject Interface: Supporting Transactional Item Modifications......Page 367
The INotifyPropertyChanged Interface: Publishing Item Change Notifications......Page 368
The IDataErrorInfo Interface: Providing Error Information......Page 369
The ICustomTypeDescriptor Interface: Exposing Custom Type Information......Page 371
The ISupportInitialize Interface: Supporting Designer Initialization......Page 373
The ISupportInitializeNotification Interface: Supporting Interdependent Component Initialization......Page 376
Where Are We?......Page 380
8 Implementing Custom Data-Bound Controls......Page 382
Extending Framework Data-Bound Controls......Page 383
Creating a Grouped Column DataGridView......Page 384
Deriving from DataGridView and Handling the CellFormatting Event......Page 386
Modifying the Painting Behavior of the Cell......Page 387
Using Custom Controls......Page 389
The User Control Test Container......Page 391
Developing Data-Bound Container Controls......Page 392
Building a Filtered Grid Control......Page 393
Adding Data-Binding Capability to a Custom Control......Page 396
Supporting Designer Initialization of Data Binding......Page 398
Specifying Binding Properties on a Control......Page 399
Supporting Delayed Initialization with ISupportInitialize......Page 401
Dynamically Determining the Properties of a Data Source......Page 406
Dynamically Populating a Combo Box Control......Page 407
Handling the ListChanged Event......Page 409
Autocompleting Input in a TextBox Control......Page 410
Autosizing Columns in the Grid......Page 414
Winding Up the Filtered Grid Example......Page 415
Building a Data-Bound Charting Control for Decision Support......Page 418
Creating a Custom Control That Draws Itself......Page 420
Defining a Custom Data Structure for Rendering......Page 422
Coding a Data-Bound Custom Control......Page 423
Defining the Custom Control Skeleton......Page 424
Initializing and Updating the Data Bindings......Page 426
Adding Bar Chart Instances to the Container......Page 428
Adding Editing Support to a Custom Data Bound Control......Page 430
Where Are We?......Page 436
9 Implementing Custom Data-Bound Business Objects and Collections......Page 438
Defining and Working with Data-Bound Business Objects......Page 439
Defining and Working with Data-Bound Business Object Collections......Page 444
.NET Framework Generic Collection Classes......Page 445
The CustomBusinessObjects Example......Page 447
Binding the Customers and Orders Objects to Form Controls......Page 449
Generating Some Test Data to Bind Against......Page 452
Setting the Textual Data-Binding Behavior of Custom Objects......Page 454
Supporting Transacted Object Editing with IEditableObject......Page 455
Supporting Object Edit Notifications with Property Change Events......Page 459
Supporting Object Edit Notifications with INotifyPropertyChanged......Page 462
Using BindingList
Creating a Custom Collection Type Based on BindingList
Taking Over the Construction Process......Page 466
Getting Some Test Data to Work With......Page 468
Adding Search Functionality to the Collection......Page 469
Adding Sorting Capabilities to the Collection......Page 471
Managing Transacted Additions to a Collection......Page 478
Raising Item Changed Events......Page 480
Adding IBindingListView Functionality......Page 482
Binding to Business Objects Through the Data Sources Window......Page 492
Where Are We?......Page 494
10 Validating Data Input and Handling Errors......Page 496
Windows Forms Validation......Page 497
Handling Validation Events......Page 498
DataGridView Validation Events......Page 501
Validation Up the Control Hierarchy......Page 502
Displaying Validation Errors with the ErrorProvider Control......Page 503
DataGridView Error Displays......Page 506
DataGridView DataError Event......Page 507
Controlling Validation Behavior with the AutoValidate Property......Page 510
Validation down the Control Hierarchy......Page 511
Extended Validation Controls......Page 513
Capturing Data Errors on Data Sets......Page 514
Providing Error Information from Custom Objects with IDataErrorInfo......Page 518
Data Concurrency Resolution......Page 522
Where Are We?......Page 523
A: Binding to Data in ASP.NET......Page 526
ASP.NET Page Processing Basics......Page 528
Data Binding in ASP.NET 1.X......Page 529
Presenting Tabular Data in a Grid......Page 530
Hooking Up Dynamic Behavior in a Code-Behind Class......Page 531
Handling Row Selecting in the Grid......Page 534
Using Data-Binding Expressions......Page 535
Data-Binding Overview in ASP.NET 2.0......Page 537
Data Sources......Page 538
SqlDataSource Control......Page 539
ObjectDataSource Control......Page 544
XmlDataSource Control......Page 546
Data-Binding Expressions......Page 547
GridView Control......Page 548
DetailsView Control......Page 551
FormView Control......Page 553
Master-Details Binding......Page 554
Hierarchical Binding......Page 557
Where Are We?......Page 558
B: Binding Data in WinFx Applications......Page 560
WinFx UI Programming and Capabilities Overview......Page 561
Writing a Simple WinFx Application......Page 564
Getting Started with a βHello Worldβ Application......Page 565
Building a Slightly More Involved Application......Page 567
WinFx Data Binding......Page 571
Data Contexts and Data Sources......Page 575
What About XAML?......Page 576
Binding a Collection to a Grid with Templates......Page 580
Control Styling in WinFx......Page 582
Where Are We?......Page 584
C: Programming Windows Forms Applications......Page 586
Your First Windows Forms Data Application......Page 587
Creating an Empty Windows Forms Project......Page 593
Working with the Toolbox......Page 594
Adding Members to the Form......Page 596
Hooking Up an Event Handler and Data Binding......Page 600
Windows Forms Designer-Generated Code (New in 2.0)......Page 602
A Brief Tour of the Windows Forms Architecture......Page 606
The Dawn of .NET ExecutionβThe Main Method......Page 609
Handling Control Events......Page 613
Displaying Other Forms......Page 615
Containing Forms Within a Parent Form......Page 616
Common Data Display Controls......Page 617
Label Controls......Page 618
Check Box Controls......Page 619
Text Box Controls......Page 620
List Box Controls......Page 621
List View Controls......Page 623
Data Grid Controls......Page 624
Creating a Custom User Control......Page 625
Absolute Positioning and Sizing of Controls......Page 628
Anchoring Controls......Page 629
Docking Controls......Page 631
Using Layout Container Controls (New in 2.0)......Page 634
Setting Tab Order......Page 635
Command and Control of Your Windows Forms Applications (New in 2.0)......Page 637
Where Are We?......Page 639
D: Accessing Data with ADO.NET......Page 640
Relational Data Access......Page 642
The Ubiquitous DataSet......Page 646
Loading Data Sets from a File......Page 648
Creating a Data Set Programmatically......Page 650
Loading Data Sets from a Database......Page 652
Loading a DataTable with a DataReader......Page 658
Master-Details DataSets......Page 660
Retrieving Data with Stored Procedures......Page 662
Updating the Database Using Data Sets......Page 663
Handling Concurrency......Page 667
Updating with Data Sets and Stored Procedures......Page 671
Searching Data Sets......Page 676
Merging Data from Multiple Data Sets......Page 678
Working with Data Views......Page 680
Working with Transactions......Page 682
Scoping Transactions with System.Transactions......Page 686
Client-Side Transactions......Page 689
Data Set and Data Adapter Events......Page 690
Reading Data into Business Objects......Page 693
XML Data Access......Page 697
Working with the XmlDataDocument Class......Page 698
Working with the XPathDocument Class......Page 702
Loading Data into an XPathDocument......Page 703
Querying XML Data......Page 704
Navigating an XML Document......Page 706
Where Are We?......Page 709
A......Page 710
B......Page 712
C......Page 713
D......Page 716
E......Page 720
F......Page 721
G......Page 722
I......Page 723
M......Page 725
O......Page 726
P......Page 727
R......Page 728
S......Page 729
T......Page 731
V......Page 732
W......Page 733
X......Page 734
π SIMILAR VOLUMES
"Brian Noyes' writing style easily captures your attention as he elaborates on all aspects of data binding in his book. He has a refreshingly clear and crisp delivery as he starts each chapter with a simple tour of each topic, and then leads you into practical concerns for sound practices and extens
Microsoft's new ClickOnce auto-updating technology can radically simplify application deployment. Using it, .NET developers and architects can deliver a powerful, smart client experience along with the easy maintenance of today's best Web applications.Microsoft Regional Director and MVP Brian Noyes
Programming Data-Driven Web Applications with ASP.NET provides readers with a solid understanding of ASP.NET and how to effectively integrate databases with their Web sites. The key to making information instantly available on the Web is integrating the Web site and the database to work as one piece
Pro Service-Oriented Smart Clients with .NET 2.0 demonstrates how Smart Clients satisfy multiple purposes. First you deploy a Smart Client application to a server and send your user base a URL. Then when a user clicks the link, the server downloads the application to the end user's machine and then
<p><p>ASP.NET is a huge advance from previous incarnations of ASP, with one of its goals being pure HTML output that achieves maximum cross-browser compatibility. The server-side event architecture tends to engender this approach, but amid the first flush of excitement its often forgotten that there