O'Reilly logo

Professional C# 2008 by Karli Watson, Morgan Skinner, Jay Glynn, Bill Evjen, Christian Nagel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 32

Data Binding

This chapter builds on the content of Chapter 26, “Data Access,” which covered various ways of selecting and changing data, by showing you how to present data to the user by binding to various Windows controls. More specifically, this chapter discusses:

  • Displaying data using the DataGridView control
  • The .NET data-binding capabilities and how they work
  • How to use the Server Explorer to create a connection and generate a DataSet class (all without writing a line of code)
  • How to use hit testing and reflection on rows in the DataGrid

You can download the source code for the examples in this chapter from the Wrox Web site at www.wrox.com.

The DataGridView Control

The DataGrid control that has been available from the initial release of .NET was functional, but had many areas that made it unsuitable for use in a commercial application — such as an inability to display images, drop-down controls, or lock columns, to name but a few. The control always felt half-completed, so many control vendors provided custom grid controls that overcame these deficiencies and also provided much more functionality.

.NET 2.0 introduced an additional Grid control — the DataGridView. This addresses many of the deficiencies of the original control, and adds significant functionality that previously was available only with add-on products.

The DataGridView control has binding capabilities similar to the old DataGrid, so it can bind to an Array, DataTable, DataView, or DataSet class, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required