The DataGrid Control

The problem with pre-designed user controls is typically that they are either simple and therefore too limited to do what you want, or they are powerful and therefore so complex that they are very difficult to learn. The DataGrid control attempts to overcome both of these constraints. Creating a simple DataGrid control couldn’t be much easier, yet there is enough power and complexity to keep you quite busy tweaking and modifying the control to do exactly what you want.

To explore both the simplicity and the power of the DataGrid control, we’ll use the process of successive approximation to get something working quickly and then to keep it working while we enhance it.

Version 1: Displaying Data

In the first iteration, you’ll create a DataGrid object and display some simple data. To get started, you need a data source, in this case an ArrayList that you’ll populate with Bug objects. You will define the Bug class, and each Bug object will represent a single bug report. For now to keep it simple, you’ll give the Bug class a few fields to hold representative information about a given code bug. Example 10-1 is the definition of the Bug class in C#; Example 10-2 is the same definition in VB.NET.

Example 10-1. The Bug class in C#

public class Bug { private int bugID; private string title; private string reporter; private string product; private string version; private string description; private DateTime dateCreated; public Bug(int bugID, string title, string reporter, ...

Get Programming ASP .NET now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.