Windows Forms: DataGrid Formatting
This sample shows how you can
retrieve data from the database, display the
data in a DataGrid, and how to format the appearance of the DataGrid.
Featured Highlights
ADO.NET is used to retrieve the information from SQL Server. The data is loaded
into
a DataSet, and the DataGrid is populated by binding to the DataSet.
The controls on this form utilize anchoring so that the form resizes
intelligently
without the developer having to write any code.
Formatting the DataGrid's appearance is accomplished using code in four button
click event
handlers. The formatting code implemented in each event handler increases in
complexity and
granularity. The buttons are named as follows (ranked in order of increasing
control over
formatting):
1. Default: Only default DataGrid formatting is used.
2. Grid Properties: Only DataGrid formatting properties are used.
3. Table Style: A DataGridTableStyle object is used to format the DataGrid.
4. Column Styles: DataGridColumnStyle objects are added to the
DataGridTableStyle object.
Requirements
Requires the release version of Visual Studio .NET Professional (or greater)
and access to the Northwind database residing in SQL Server or the Microsoft
Data Engine (MSDE). To install MSDE, do the following:
1. Open the Start menu, then click Programs, the click Microsoft .NET Framework
SDK, and then click Samples and Quickstart Tutorials.
2. Click "Step 1: Install the .NET Framework Samples Database".
3. Open a command window, and CD to <FrameworkSDK>\Samples\Setup
This is typically :
C:\Program Files\Microsoft Visual Studio .NET\FrameworkSDK\Samples\Setup
4. Type: osql -E -S (local)\NetSDK -i InstNwnd.sql
Running the Sample
Simply Press F5.
See also