Data Binding with Windows Forms 2.0: Programming Smart Cl... and over one million other books are available for Amazon Kindle. Learn more

Data Binding with Windows Forms 2.0: Programming Smart Client Data Applications with .NET 1st Edition

25 customer reviews
ISBN-13: 978-0321268921
ISBN-10: 032126892X
Why is ISBN important?
This bar-code number lets you verify that you're getting exactly the right version or edition of a book. The 13-digit and 10-digit formats both work.
Scan an ISBN with your phone
Use the Amazon App to scan ISBNs and compare prices.
Have one to sell? Sell on Amazon
Buy used
Buy new
Amazon Price New from Used from
"Please retry"
Paperback, January 22, 2006
"Please retry"
$16.99 $0.01
More Buying Choices
17 New from $16.99 33 Used from $0.01
Free Two-Day Shipping for College Students with Amazon Student Free%20Two-Day%20Shipping%20for%20College%20Students%20with%20Amazon%20Student

InterDesign Brand Store Awareness Textbooks
$53.59 FREE Shipping. In Stock. Ships from and sold by Gift-wrap available.

Frequently Bought Together

Data Binding with Windows Forms 2.0: Programming Smart Client Data Applications with .NET + Windows Forms 2.0 Programming (Microsoft .NET Development Series) + Windows Forms Programming in C#
Price for all three: $129.70

Buy the selected items together

Editorial Reviews

About the Author

Brian Noyes is a software architect, trainer, writer, and speaker with IDesign (, a premier .NET architecture and design consulting and training company. He has been developing software systems for more than fifteen years, speaks at many major software conferences around the world, and writes for a variety of software journals and magazines.

Excerpt. © Reprinted by permission. All rights reserved.

When I first started discussing this book with the editors at Addison-Wesley, I was a little skeptical. My gut reaction was, “Will anyone need a whole book focused on data binding?” I mean, Windows Forms is just GUI stuff, right? You drag this, you drop that, you hook up a few event handlers, and you move on to build the rest of your enterprise application—all the middle-tier goo that ties your head in knots.

As I thought more about it, I realized that a significant percentage of the work that people do in Windows Forms applications is centered around data binding, and most of the problems developers encounter are related to getting data-binding scenarios to work correctly. Add to that the multitude of new capabilities in Windows Forms 2.0 and Visual Studio 2005 related to data binding, and I quickly became convinced that this book would be a good idea. Hopefully you will agree after you have finished reading it.

Data binding is a powerful capability that has finally matured in Windows Forms 2.0 through the capabilities in the .NET Framework classes, combined with the rich designer support provided by Visual Studio 2005. By using data binding properly, you can save yourself from writing a lot of unnecessary code, provide your users a rich interactive experience for working with data that functions well, and produce code that is easy to maintain. To get it working correctly across a variety of use cases, you need to know more than how to set a few properties on controls—you need to understand what is going on under the hood, especially if you want tosupport complex scenarios that require going beyond the basic capabilities of the data-binding components in the .NET Framework.

Due to the growth of smart client architecture, Windows Forms applications are becoming more prominent in business systems. Web browser-based applications leave a lot to be desired; they cannot support many of today’s common scenarios. They don’t harness the capabilities of the client machine, and they are constrained by the request-response model of browser-based applications and the connectivity issues that surround them. So the importance of being able to code complex data application scenarios in Windows Forms is growing, and luckily the capabilities in .NET services are rapidly maturing to keep pace.

Who Should Read This Book?

The primary audience for this book is intermediate to advanced Windows Forms developers who want to learn about the new data-binding features in Windows Forms 2.0 and refine their coding practices for data-bound applications. This book dives deep into advanced features of the data-binding mechanisms in Windows Forms, data-bound controls, working with data sources, and creating custom data-bound objects and collections. If you spend a significant amount of time working with data in Windows Forms applications, then this book is for you.

If you are a beginner Windows Forms developer, this book will help you quickly learn how to support data binding. Many of the features in Windows Forms 2.0 take developers through wizards and designer features that are helpful for beginning programmers, and you will learn about those features in this book. In addition, Appendixes C and D are geared for beginner programmers to get up to speed on the basics of Windows Forms and data access.


Developing applications is more about tools and less about code. However, there is a lot of code in this book, and I have adopted some common conventions to help make things easier. References to classes, variables, namespaces, and other artifacts that manifest themselves in code are in a monospace font; this helps you distinguish an instance of the DataSet class from a conceptual discussion of data sets. Short code listings are presented inline within the text using a different monospace font.

Longer listings use a similar font, but are identified with listing numbers, for example, Listing 4.1. Within code listings, bold highlights particularly relevant portions of the code, especially “evolving code.” When I remove details that aren’t relevant to a discussion, you’ll see a comment with an ellipsis (//...). This means that more code is needed to complete the example or more code generated by the designer exists, but you don’t need it to understand the concept. On occasion, explanatory comments show context.

I use a conversational tone to discuss the kinds of objects you deal with in data-binding scenarios, for example, when describing the DataSet class in this book. However, much of the time when discussing data sets I am not talking about an instance of a DataSet class, but of an instance of a derived typed DataSet class. Although it would still be technically correct to refer to that class as a DataSet because it “is a” DataSet through inheritance, I find it annoying when too many words are called out as a code artifacts. So, when something really is a code artifact and can only be discussed correctly in that context, it’s set in the monospace font. I favor the terms data set, datatable, and table adapter when discussing concepts surrounding those types of objects, and reserve DataSet, DataTable, and CustomersTableAdapter for citing a specific class type or instance, and the capabilities defined by that code artifact.

Discussing components and controls can also be confusing, depending on how precise you want to be with your language. Technically, all controls in Windows Forms are components, because the Control class derives from the Component class. Many of the concepts surrounding data binding apply to both components, such as the BindingSource component discussed in depth in this book, and controls, such as a DataGridView control. Unfortunately, many people think of components as nonvisual objects that are used by your form and controls as objects that have a visual rendering on your forms. To avoid having to say controls and components ad nauseam, when I discuss a concept that applies to both nonvisual components and controls, I simply say components. So when you see components, think “this applies to controls as well, because they inherit from components.”

System Requirements

This book was written with the code base of .NET 2.0 and Visual Studio 2005 over the course of Beta 1, several Community Technical Previews, and ultimately Beta 2. The code presented in this book runs with Beta 2. I worked closely with the Windows Client product team at Microsoft, and there are no feature changes planned between Beta 2 and product release. However, some minor syntax may change between production and the release of .NET 2.0. If they do affect the code or concepts, I will provide corrections through the Web site for the book (, as well as updated code that will run on Visual Studio 2005 once it is released.

If you plan to run the samples available on the book’s Web site, or the walkthroughs and code listings in the book, you will need Visual Studio 2005 installed on your machine, and you will need access to a SQL Server 2000 or 2005 database server on which the Northwind sample database has been installed. Additionally, you will need to have permissions on that database to create new databases for some of the samples.

There are multiple versions of Visual Studio 2005 to choose from. All of the features discussed in this book even work in the Express versions of Visual Studio 2005, which are free. You can develop all of the samples in this book in Visual C# 2005 Express or Visual Basic 2005 Express with SQL Server 2005 Express, but because Express versions of Visual Studio don’t support data connections using server paths (they only support file path-based connections to SQL Express databases), you will have to create the sample databases and data in SQL Express, and then alter the connection strings and the way you set up connections based in Express.

The samples and scripts included in the book assume you are working on a machine with a standard, professional, or enterprise version of Visual Studio 2005 installed, along with a default instance of either SQL Server 2000 or 2005 on your local machine. To run the samples without that configuration will require modifying the connection string settings for all of the samples that run against a database. The modifications needed are discussed on the book’s Web site, and the differences in connection strings are highlighted in many places in the sample code.

Additionally, Northwind doesn’t ship with SQL Server 2005, but is available as a separate installable download that will work with SQL Server 2005 from MSDN Downloads at FamilyID=06616212-0356-46A0-8DA2-EEBC53A68034&displaylang=en. The download provides scripts and MDF files that can be attached to SQL Server 2005 or used with SQL Server 2005 Express.

Choice of Language

I chose to write this book in C#. The download code is available in both C# and Visual Basic code. It is a fact of life that there will continue to be a mix of C# and Visual Basic available in articles, books, and samples for a long time to come. Even though I prefer C# myself, I am not a language bigot and feel Visual Basic is a solid choice for developers who have a strong background in earlier versions of Visual Basic.

I firmly believe that to be an effective .NET developer, you need to be able to read code from either language, even if you spend most of your time with one. If you aren’t already comfortable reading C# code, I encourageyou to use this opportunity to get comfortable reading it. It will expand your horizons in terms of the amount of reference material that is available to you, it may help you in your job, and it will give you bragging rights over the many silly and close-minded C# developers who cannot read Visual Basic.

Coding Standards

Yes, I have coding standards, and you should too. It is as simple as that, but unfortunately not done nearly enough by development organizations. Coding standards are an important tool in making sure that code is bug free, but they are even more essential for making sure that your code base is maintainable. Code written by one developer on your team should look like the code written by all the other developers so that it can be maintained and extended if necessary. Code reviews go hand-in-hand with your coding standard and are also something that should be a regular part of your development process.

We have an excellent coding standard at IDesign, which can be downloaded from our site at You can use as is, or you can use it to develop your own coding standard. Our standard includes a lot of information that goes beyond simple syntax; it has a lot of best practices for .NET development and design.

For the code presented in this book, I used the IDesign coding standard for naming member variables, properties, methods, and event handlers. Any member of a class, whether just a variable or a control on a form, is given a prefix of m_ and PascalCasing is used for the rest of the name. This is different from the Microsoft standard (which varies somewhat across different product teams), and that is okay. You can use whatever standard you want, as long as you are consistent. I won’t go into the arguments and justifications of coding standard here, but I want to short-circuit any complaints or e-mails that might result.

You will see code snippets where this convention isn’t followed (when I am discussing designer-generated code), because the naming conventions generated by the designer differ from our coding standard. So when discussing the raw code generated by the designer, I will demonstrate theway they generate the code; when I am writing code or focusing on other aspects of the code, I will rename the things generated by the designer to comply with IDesign coding standard.

Code First Versus Design Features First

One of the hardest decisions I had to make when writing this book was the order in which to present the concepts: Should I start by discussing code that you can write by hand to get things working in an application, or should I start by walking through all the different combinations of design features in Visual Studio that will write the code for you?

You can get a lot of data binding done through a combination of drag-and-drop interactions in the Visual Studio designer and by setting properties for objects on a form in the Properties window and other windows. When coding production applications, the Visual Studio designer is where you will start 90 percent of the time. Ultimately, those interactions are just having the designer write the code so that you don’t have to. This allows applications to be written much faster and helps figure out how to get data-binding scenarios working even if you don’t really understand the code that is being generated.

If this book’s goal were to cover more introductory level concepts across a wider scope of topics, then sticking to the designer with a little bit of code explanation would be sufficient. However, my goal is to provide a deep technical tutorial on all aspects of Windows Forms data binding for developers who want to tackle complex scenarios that go beyond the designers. Whenever you thoroughly want to understand what is going on, you need to really think about things at the code level, not at the level where the designer, wizards, and windows in Visual Studio are doing magic things for you.

As a result, I chose to tackle things from a code-first perspective. As you progress through the book, for most common scenarios there are ways to get the Visual Studio designers to write most or all of the code for you. But to maintain that code and to go beyond those common scenarios, you also need to be able to write that code by hand (if need be), and know what all the right pieces and parts are to hook together. The chapters are arrangedto first introduce a concept and to show you the raw code that enables you to get that concept working. Then, if there’s a corresponding designer way of getting that code written, that’s covered next.

For example, Chapters 3 and 4 describe data-binding mechanisms in Windows Forms and how to write the code to hook up controls to data sources. Then Chapter 5 shows how to use the Data Sources window to write a lot of that code for you. If you find it easier to learn by seeing things through the designer first and then unraveling the code, you might want to read the chapters and sections focused on the designer features first, and then return to previous sections to understand the code that was written on your behalf.

Northwind—The Database That Will Never Die

To show examples of data binding, you need some data to work with. One approach is to create new databases with new data in them to use in examples. While that may provide more interesting data for the samples, it has the downside of requiring you to learn a new schema and to set up those data sources on your machine to try out the demos. Because most interesting data usually belongs to someone, to avoid having to worry about copyrights and permissions to use the data, I created some sample databases for a few simple examples, but most of the examples use the tried-and-true Northwind database that is installed as part of the samples for SQL Server 2000 with a typical install. Also, through some downloadable scripts from Microsoft, you can get a Northwind instance installed on SQL Server 2005 or SQL Express 2005 as well. See the book’s Web site for detailed instructions on how to do that.

Although many people are bored with Northwind (I count myself in that crowd), it does have the advantage of familiarity, and it is ubiqui-tously available and can be added easily as long as you have SQL Server. If you are already familiar with Northwind, you know about the Customers, Orders, and Order Details tables; if you aren’t, you can learn this fairly simple schema easily.

Overview of the Book

This book starts with some background in peripheral concepts surrounding data binding: how data-bound Windows Forms applications fit into the big-ger picture of distributed application architecture, particularly smart clients. It then delves into the new data-binding features in Windows Forms 2.0 and more advanced topics. The following is an overview of each chapter.

Chapter 1, Building Data-Bound Applications with Windows Forms, introduces the concepts of data binding, along with a quick walkthrough sample using the designer to generate a data-binding application. The data application architecture lays the groundwork for the other pieces to create a rich and robust data application.

Chapter 2, Working with Typed Data Sets and Table Adapters, shows how to use the new Visual Studio 2005 typed data set designer to generate most of the data access code needed in applications through simple drag-and-drop and wizard operations in the designer. It discusses the benefits of typed data sets, how to create and use them, and how to create and use typed table adapters to fill and update those data sets. It also covers how to use table adapters to perform ad hoc and custom queries.

Chapter 3, Introducing Data Binding in Windows Forms, starts delving into coding mechanisms in Windows Forms for data binding. It demonstrates how to perform simple and complex binding of data to controls, and introduces BindingSource, one of the most important data-binding tools available in .NET 2.0.

Chapter 4, Binding Controls to Data Sources, builds on Chapter 3, further peeling back the layers on the use of the BindingSource component, and includes detailed coverage of using the Binding object for simple binding with automatic formatting and for handling binding events.

Chapter 5, Generating Bound Controls with the Visual Studio Designer, introduces the designer features for generating data-binding code: drag-and-drop operations, wizards, and property grid interactions. It covers the Data Sources window in detail and the associated wizards.

Chapter 6, Presenting Data with the DataGridView Control, provides in-depth coverage of the DataGridView control, a rich tabular control for Windows Forms that is new in .NET 2.0. The chapter steps through basic usage as well as advanced scenarios and describes customizing the contentof cells, implementing cell-oriented grids, handling grid events, as well as many other features of the grid.

Chapter 7, Understanding Data-Binding Interfaces, discusses the many interfaces involved in making the data-binding process work, and shows you which interfaces you need to implement when and what is involved. This chapter will help cement your understanding of the real mechanisms that drive data binding.

Chapter 8, Implementing Custom Data-Bound Controls, shows how to implement custom controls in Windows Forms for rendering data and what is required at the control level to use the data-binding interfaces exposed by data collections and objects. It also discusses additional things to consider when creating data-bound controls.

Chapter 9, Implementing Custom Data-Bound Business Objects and Collections, covers how to create custom business objects and collections that you can use in data binding. It discusses implementing appropriate interfaces, and shows samples and how they get used. It provides detailed coverage of the BindingList generic class, which makes creating custom collections of data objects a snap.

Chapter 10, Validating Data Input and Handling Errors, describes validation mechanisms in Windows Forms and how to properly harness those mechanisms. It discusses error handling at the form and data-binding levels, along with strategies for managing concurrency violations.

Appendix A, Binding to Data in ASP.NET, gives a quick introduction to ASP.NET data binding for developers who will have to write both Windows and Web applications.

Appendix B, Binding Data in WinFx Applications, looks at the data-binding mechanisms in WinFx, the next generation presentation subsystem for Windows, so you can compare it to Windows Forms data binding.

Appendix C, Programming Windows Forms Applications, introduces the fundamentals of building Windows Forms applications. Written for beginning Windows Forms programmers, it will make the rest of the applications in the book understandable. It isn’t intended to be a comprehensive lesson on all aspects of Windows Forms programming, just the essentials.

Appendix D, Accessing Data with ADO.NET, is a comprehensive overview of performing data access with ADO.NET. It covers many concepts, including retrieving and updating data with data sets and data readers, working with stored procedures, and managing transactions, as well as how to work with XML as a data source in .NET.

Sample Download Code and Updates

You can download all of the sample code used in this book at I will also post any changes, corrections, and updates relevant to the book at that location, and will post instructions on how to modify the sample code to run on the Express versions of Visual Studio and SQL Server 2005.

You can also find links to all of the above at the book’s page on Addison-Wesley’s site at


Shop the New Digital Design Bookstore
Check out the Digital Design Bookstore, a new hub for photographers, art directors, illustrators, web developers, and other creative individuals to find highly rated and highly relevant career resources. Shop books on web development and graphic design, or check out blog posts by authors and thought-leaders in the design industry. Shop now

Product Details

  • Paperback: 736 pages
  • Publisher: Addison-Wesley Professional; 1 edition (January 22, 2006)
  • Language: English
  • ISBN-10: 032126892X
  • ISBN-13: 978-0321268921
  • Product Dimensions: 7 x 1.4 x 9.2 inches
  • Shipping Weight: 2.2 pounds (View shipping rates and policies)
  • Average Customer Review: 4.7 out of 5 stars  See all reviews (25 customer reviews)
  • Amazon Best Sellers Rank: #1,037,680 in Books (See Top 100 in Books)

More About the Author

Discover books, learn about writers, read author blogs, and more.

Customer Reviews

Most Helpful Customer Reviews

20 of 21 people found the following review helpful By Jack D. Herrington on January 25, 2006
Format: Paperback
This book is about so much more than data binding. I'm not sure why they titled it this way. The book is really about forms from start to finish, including what is new in the 2.0 framework. It's an excellent work on proper forms programming and data flow. I highly recommend this book for anyone doing a lot of Windows forms work.
Comment Was this review helpful to you? Yes No Sending feedback...
Thank you for your feedback. If this review is inappropriate, please let us know.
Sorry, we failed to record your vote. Please try again
18 of 20 people found the following review helpful By A regular guy on April 25, 2006
Format: Paperback Verified Purchase
This book is an excellent introduction to Windows Forms in .NET 2.0, but is really not titled correctly. In particular, the subtitle "Programming Smart Client Data Applications with .NET" is blatantly misleading considering:

1. Offline data access (or disconnected mode usage), by definition a core component of smart clients, is covered for a total of 3 sentences in this book.

2. Other relevant smart client topics, such as ClickOnce deployment, are either addressed in the single "What is a smart client?" section (one page!) or ignored altogether.

I'm giving this book 4 stars because it really is a great book for those venturing into building Windows Forms 2.0 applications (also touching relevant topics like ASP.NET, WinFX and XAML), but the title should have ignored any reference to smart clients altogether. If you're a developer looking for a great resource for building apps in VS.NET 2005, this is the book for you. If you're looking for a smart client resource like I was, this is not it.
Comment Was this review helpful to you? Yes No Sending feedback...
Thank you for your feedback. If this review is inappropriate, please let us know.
Sorry, we failed to record your vote. Please try again
21 of 24 people found the following review helpful By Amazon Customer on July 25, 2006
Format: Paperback
This book (as the title suggests) is strongly geared towards data binding in the context of "Smart Clients." From this book, I take "Smart Client" to mean that you are only showing tabular data directly from databases. He spends 80% of the book talking about binding to data bases with the DataGridView control. Because of this, other aspects of data binding are neglected.

After reading this book, I still had no idea how to create custom properties on a control that can be bound to with simple data binding (use the Bindable attribute, which isn't even mentioned in the book).

He does not sufficiently cover writing controls that want to use non-list data or the interfaces that non-list data objects must implement to be bound to controls.

In the end, this book is just a big example of how to use data binding, as long as you want to do exactly what is done in the samples (bind tabular data to grid views). Very little useful information that can be used to do anything outside this narrow pattern is provided.

UPDATE: I wish I could drop my rating to 2 stars. Every time I try and use this book, I'm infuriated by the lack of any useful information.
Comment Was this review helpful to you? Yes No Sending feedback...
Thank you for your feedback. If this review is inappropriate, please let us know.
Sorry, we failed to record your vote. Please try again
9 of 10 people found the following review helpful By W. Gant on March 20, 2006
Format: Paperback
What's really cool (and missing in all the reviews and sample chapter) is how the author actually does things like they would be done in a real project. For instance, his typed dataset definition is in a dll, not lumped into the main project. He seems to make a continual effort to keep things loosely coupled and logically separated, just like seasoned programmers do. His assumption seems to be that the reader wants to learn the right way to do things, rather than just getting a surface level understanding of major concepts.

It is blatantly obvious that while the author is an excellent writer, that he got his start as an excellent developer (unlike many authors, who only code so that they can write a book about it). By the time I got 100 pages into the book, I felt like I had gotten my money's worth. The book is very informative, and is not full of filler material like so many others.

This is hands-down the most clear and helpful book on .NET I've read to date.
Comment Was this review helpful to you? Yes No Sending feedback...
Thank you for your feedback. If this review is inappropriate, please let us know.
Sorry, we failed to record your vote. Please try again
4 of 4 people found the following review helpful By Blue Cat on January 19, 2007
Format: Paperback
This is a really great book. Like most technical books it covers a lot of ground:

1. Shows through example how data binding works in windows: how to use the Binding class to bind a property on a control to a property on an object; how the new .NET 2.0 BindingSource class is used and why it was created; and a clear explanation of the currency manager and how the BindingSource class replaces it. I didn't even know you could bind arbitrary properties on an object to a property on a control. This book showed me how to do it. Too Cool!

2. A detailed explanation of how to use and extend the DataGridView. It is the best one stop shopping treatment of the DataGridView I have seen anywhere.

3. How to implement custom data-bound controls in windows forms.

4. A detailed explanation of the Data-Binding interfaces, including how to bind the DataGridView to something other then a DataTable.

5. And so much more...

I consider this one of the few .NET books worth reading. One big plus about this book is after the first couple of chapters you can skip around and read what you need to get your job done.

Using the information from this book I was able to create an adapter to our custom business object and display the data in a data grid view. Using the data grid view the user can perform the standard CRUD (create, read, update, and delete operations) on the data. This provides a nice addition to our graphical rendering. Big thanks to the author. I couldn't of done it without this book.
Comment Was this review helpful to you? Yes No Sending feedback...
Thank you for your feedback. If this review is inappropriate, please let us know.
Sorry, we failed to record your vote. Please try again
1 of 1 people found the following review helpful By P. Valentine on September 5, 2006
Format: Paperback
This book lived up to and surpassed my expectations.

Going into this book, I had very little knowledge of how to implement data binding support for my custom entity classes. After reading this book, particularly the custom entity object chapter, I was able to implement very rich data binding support (filters, sorting, error provider support, etc.) to my custom classes.

Of course, all of the various pieces of information on how to implement this support is out there in MSDN or in web articles here and there. But it was well worth the price of the book to have all of these pieces put together in this cohesive text.

I thought that the book started off a bit slow, but after the 2nd or 3rd chapter, it quickly picked up with the technical details and provided everything that I needed to know.

I would highly recommend this book if you need to implement data binding support yourself.
Comment Was this review helpful to you? Yes No Sending feedback...
Thank you for your feedback. If this review is inappropriate, please let us know.
Sorry, we failed to record your vote. Please try again

Most Recent Customer Reviews

Set up an Amazon Giveaway

Amazon Giveaway allows you to run promotional giveaways in order to create buzz, reward your audience, and attract new followers and customers. Learn more
Data Binding with Windows Forms 2.0: Programming Smart Client Data Applications with .NET
This item: Data Binding with Windows Forms 2.0: Programming Smart Client Data Applications with .NET
Price: $53.59
Ships from and sold by

Want to discover more products? Check out these pages to see more: software development, .net programming, software testing