The Data Grid Legacy

Developers have been using grid controls for years. In the pre-.NET world, developers often relied on ActiveX controls like the MSFlexGrid, which provides a solid formatting model and access to individual cells. Though controls like the MSFlexGrid still can be used in .NET, they obviously can't support .NET data binding. If you want to use them, you'll need to write painstaking code to iterate through the rows of your data source and copy values into the grid.

The DataGrid was the first native .NET solution for a data-bound list control, and it's included with every version of the .NET Framework. The DataGrid has an almost deceptive appearance of simplicity—although you can bind data with a single line of code, you might need to write dozens more to accomplish a seemingly easy task like applying a custom background color to a cell. In fact, the first edition of this book included a mere seven pages of information about the DataGrid, because most developers outgrew its feature set long before they had the chance to use it in a realistic application.

Some of the limitations of the DataGrid include:

• Limited ability to customize its appearance. Some details, like column formatting, are fairly easy to change. Other details, like individual cell formatting, are much more challenging and require writing custom DataGridColumnStyle classes. Still other details, like formatting an entire row or modifying the appearance of table links, are nearly impossible.

• No easy way to display pictures in cells. Again, if you want to use this feature you'll need to implement it yourself with a custom DataGridColumnStyle class that contains dozens of lines of code.

• Limited support for formatting text and numbers. You can use the standard number formats, but if you need to apply a custom format—for example, "translating" a numeric status code into a text string—you're on your own.

• Limited ability to access individual cells. The DataGrid doesn't make it easy to change or read arbitrary cell values. Instead, you need to work through the bound data source. If you want to display information in a DataGrid without using data binding, you're out of luck.

• Limited support for modifying the DataGrid programmatically. Tasks like changing column order or adding custom button columns are impossible.

• No ability to customize the DataGrid error messages. If the user attempts to make an invalid edit to a cell, you're stuck with cryptic error messages provided by the .NET Framework.

For most developers, the best they could hope for was to discover these issues before committing their applications to use the DataGrid. Needless to say, the third-party control market had great success selling custom grid controls for .NET 1.0 and 1.1.

+1 0

Post a comment