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, ...

Get Professional C# 2008 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.