Article Options
Premium Sponsor
Premium Sponsor

 »  Home  »  .NET Newbie  »  The Hidden Power of the DataGrid Control - Part 1
 »  Home  »  Data Programming  »  The Hidden Power of the DataGrid Control - Part 1
 »  Home  »  Windows Development  »  Win Forms  »  The Hidden Power of the DataGrid Control - Part 1
The Hidden Power of the DataGrid Control - Part 1
by Dmytro Lapshyn | Published  01/13/2005 | .NET Newbie Data Programming Win Forms | Rating:
Dmytro Lapshyn

Dmytro Lapshyn works as a CTO for Validio Ukraine, which is an official partner of Validio Software, LLC. He previously worked as a programmer in a volunteer student scientific and production group "Programmist" of Kharkov Technical University of Radio-Electronics.

During more than 7 years of his programmer career Dmytro has developed various applications including desktop, client-server and Internet development. He has been working with Microsoft technologies since 1998 and has been developing with Microsoft .NET since the Beta 2 release in 2001. His primary areas of expertise are Visual Basic, ASP, COM+ and .NET.

Dmytro is 27 years old and lives in Kharkov, Ukraine. He has a Bachelors and a Masters degree in Computer Systems Security from Kharkov Technical University of Radio-Electronics.

Company Profile

Founded in 1992, Alis Software successfully operated in software development market for 5 years. In 1997 the company was acquired by Miik Ltd and became its Information Technologies Division. Three years of flourishing accompanied by the dynamic growth made the division the priority of the company business and since 2000 Miik Ltd. almost entirely proceeded to producing software, computer graphics, and Web applications in partnership with foreign and national companies for clients both in Ukraine and abroad.

In summer 2005, Information Technologies Division of MIIK Ltd. was reorganized into Validio Ukraine.

Validio Software provides outsourced software development services to high-tech companies and businesses that rely on technology. Based in Seattle, Washington, Validio's services include design, management, and implementation of complete projects using experienced development teams, as well as providing skilled development resources for customer driven projects. By maintaining staff of qualified software developers and experienced project managers in both the U.S. and Ukraine, Validio offers its clients technical expertise that is both scalable and cost effective.

 

View all articles by Dmytro Lapshyn...
Introduction

Part 1

Introduction

Data Grid is one of the most widely used types of controls among developers. Many kinds of data have a tabular nature and are best represented as a grid on a computer screen. The importance of providing users with really consistent and intuitive user interface can hardly be underestimated, and a well-tailored grid could play a primary role in many user interface concepts.

Windows Forms developers are lucky, as Microsoft has included a ready-made DataGrid control into both of the Windows Forms and Web Forms sub-systems of its .NET Framework. However, many developers who have used the Windows Forms DataGrid control might have had a feeling of it being somewhat rigid or even limited. In other words, while some customizations can be achieved with several mouse clicks or keystrokes, and some others can be done with just a few lines of code, there are amendments which either require significant efforts or cannot be implemented at all. For example, there is no way to alter column header appearance other than taking over painting of the whole grid exterior.

Having bumped into several such limitations by myself, and having spent long hours on searching the Internet and digging the MSDN Library, I have decided to share my DataGrid experience with the developer community in hope to save valuable time and even more valuable nerve cells for those who accepts the DataGrid challenge in a quest for better user interface experience.

A Closer Look

The DataGrid control requires quite a complex environment with a number of helper objects (see Figure 1: Data Grid and its Environment). This environment is usually created behind the scenes, as DataGrid is smart enough to provide reasonable defaults. When these defaults are not satisfactory, the developer can always take part in the environment creation process and replace the default instances of the helper objects with customized ones.

As shown on Figure 1: Data Grid and its Environment, the DataGrid environment consists of the two main areas – the Look and Feel area and the Working with Data area. The Working with Data area is responsible for enabling interaction between the DataGrid and the bound data source. The Look and Feel area is responsible for DataGrid appearance and behavior and enables the developer to customize various DataGrid user interface aspects such as background color, column widths or even custom column styles. We will get back to the Look and Feel area later and now will focus on how the DataGrid works with data.


DataGrid and its environment
Figure 1: Data Grid and its Environment


A Few Words on Data Binding

We will begin our story with a few words on how Windows Forms data binding works. When a Windows Forms control is bound to a data source, a link called binding is established between the control and the data source. This link is responsible for supplying the control with data from the data source as well as for sending back the updated data. In addition, the link can take care of formatting the data for display and parsing the user input if necessary. The link logic is encapsulated in the System.Windows.Forms.Binding class

Another group of objects called binding managers are responsible for synchronizing controls bound to the same data source. They maintain current position within the data source and facilitate data addition, modification and removal. Binding managers inherit from the abstract System.Windows.Forms.BindingManagerBase class. There are two standard implementations of the binding managers – CurrencyManager and PropertyManager. You may find out more about these classes from the MSDN Library documentation.

Binding managers are in turn governed by binding contexts. Binding contexts are in charge of creation, storing and returning binding managers for each unique combination of a data source and a data member. There is only one binding context object per form.

All binding managers within a form are synchronized, so the data binding mechanics ensures that all binding managers for each unique combination of a data source and a data member maintain the same position.

Sponsored Links