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.

Comments    Submit Comment

Comment #1  (Posted by an unknown user on 01/15/2005)
Rating
The article didn't address my major question about datagrids, but it was well written, very insightful and helpful. The more information about the confounding datagrid control I can get my hands on, the better!

Thanks for the article - looking forward to the next.


 
Comment #2  (Posted by an unknown user on 02/05/2005)
Rating
very helpfull thanks !
 
Comment #3  (Posted by an unknown user on 02/07/2005)
Rating
Seems like VB.net is a great tool but the MS documentation sucks. I can see many people are not getting it yet even with good programmers trying to explain it all. VB.Net won't get going very well until the documentation is much, much better and many tutorials are written by bloodied warriors like Dmytro. Thanks for trying to help us poor mortals.
 
Comment #4  (Posted by an unknown user on 02/08/2005)
Rating
Seems like VB.net is a great tool but the MS documentation sucks. I can see many people are not getting it yet even with good programmers trying to explain it all. VB.Net won't get going very well until the documentation is much, much better and many tutorials are written by bloodied warriors like Dmytro. Thanks for trying to help us poor mortals.
 
Comment #5  (Posted by an unknown user on 03/05/2005)
Rating
It helps me easily...
 
Comment #6  (Posted by an unknown user on 03/16/2005)
Rating
I liked the way the architecture is explained. Exactly what I looked for.
 
Comment #7  (Posted by an unknown user on 03/26/2005)
Rating
The Microsoft documentation on the datagrid is terrible. They describe the millions of bits but leave it to the developer to try and figure how all the bits work together. Thanks for trying to provide a better description.
 
Comment #8  (Posted by an unknown user on 03/30/2005)
Rating
because very introductory information
 
Comment #9  (Posted by an unknown user on 03/31/2005)
Rating
May have been better if he went through an example
 
Comment #10  (Posted by an unknown user on 04/05/2005)
Rating
Good overview on the general architecture of the list Binding concept (information terribly lacking in MS documentation). If I would have found this article first, all the other stuff I found on binding grids would have made much more sense (as they do now, after reading this).
Hope to see part 2 about the presentation-side (the 'styles') very soon...
 
Comment #11  (Posted by an unknown user on 04/14/2005)
Rating
it was a silver lining otherwise datagrid really had me turned inside out
 
Comment #12  (Posted by an unknown user on 05/11/2005)
Rating
I understand the use of CurrencyManager but I have yet to figure out when I would enter a datagrid.DataMember. What DataMember as it is always null whenever I inspect the value passed? Microsoft's Help documentation is very poor on this topic. The last section of Final I had to learn on my own...that is execute datagrid.EndEdit and CurrencyManager.EndCurrentEdit.
 
Comment #13  (Posted by an unknown user on 05/28/2005)
Rating
This article is very good but i need to ask if i need to make a search for a value in the data grid .in Oracle Forms i make EnterQuery and then i typed the word which i need to search for in the cell which i wanna search in and then i ExecuteQuery then the results appears on the grid or TextBoxes .
so if i have a datagrid has 3 columns (CODE , NAME , LOC) and i wanna make a query for the "TX" in the LOC column how can i do it .......
if u have answer plz send me mail at eagle_165@hotmail.com
thanks alot

 
Comment #14  (Posted by an unknown user on 07/17/2005)
Rating
Excellent,The description was so visually critical,i can't wait for Part2.This is .Net
 
Comment #15  (Posted by an unknown user on 07/18/2005)
Rating
Like many of the other Posts I have had a tough time with the documentation. I think it was written for the people who don't need it. Thanks for explaining this subject in a way both Programmers with experience and those like myself, the ones struggling to learn can use..
Thanks again.
Rattlemouth

 
Comment #16  (Posted by an unknown user on 07/22/2005)
Rating
Because there is a lake of codeing explaination for this reeasion 50%50%
 
Comment #17  (Posted by an unknown user on 10/07/2005)
Rating
helps me solve a problem that got me stuck for days.
 
Comment #18  (Posted by an unknown user on 10/09/2005)
Rating
Excellent!!! I've been working on how to tell programatically the datatable to add the last editting row of a datagrid and you've given me the answer! This is great!Thank You!
 
Comment #19  (Posted by Mike on 10/20/2005)
Rating
very nice work on the article, but i think the images are linked incorrectly... the ones i see are screenshots of installing webparts not the datagrid... other than that excellent information you have here.
 
Comment #20  (Posted by an unknown user on 10/24/2005)
Rating
ITs great article, all my doubts are cleared. by bkvijayanand.
 
Comment #21  (Posted by aneesh on 10/29/2005)
Rating
This is very help full.But please tell me how we can add rows at runtime.
 
Comment #22  (Posted by an unknown user on 12/18/2005)
Rating
Help me solve an immediate problem with automating default values.
Many Thanks
 
Comment #23  (Posted by an unknown user on 06/30/2006)
Rating
The dbGrid is trash, but at least there is advice that is right here.
 
Comment #24  (Posted by an unknown user on 10/17/2006)
Rating
Good. But I was looking for how to display combo box in a cell which is not covered in this article.
Asim
 
Comment #25  (Posted by an unknown user on 01/04/2007)
Rating
I am not not able to understand all.
I got 1/3.
This article does't tell how to
implement this in a project.
soorajpv,calicut,kerala,india
 
Comment #26  (Posted by Mohammed Akbar on 02/12/2007)
Rating
Binding,Currency manager,Binding Context and editing logic very well explained. How ever i would like to add something here, in the final section u said we have to have tablestyle to use datagrid.endedit method, but without table style also it can used by giving null value for columnstyle and -1 for rowindex as mentioned below.
datagrid.endcurrentedit(null,-1,false)

 
Comment #27  (Posted by an unknown user on 04/02/2007)
Rating
because i have searched the world over for information on user interfaces and this brave man had the courage to call it datagrids...and because you made techical simple....as someone said for us poor mortals...why is microsoft so technical...sorry forget that
 
Comment #28  (Posted by an unknown user on 05/10/2007)
Rating
Good Aticle.Actually i need to know about Function "Column Started Editing method".Is there any way to indicate
that grid is being updated, through this method.I mean I want to set flag.
Iam not getting on what basis i should keep. Please help me.MailID=narendra.p@inteqsolutions.com

 
Comment #29  (Posted by an unknown user on 08/19/2007)
Rating
Excellent information, very well explained, altough there are no code examples but even then it is a great article, i would incourge author to provide detail relevant code examples.
 
Comment #30  (Posted by Ather on 08/19/2007)
Rating
Great article, infact one of the best articles i have ever seen on datagrid, but i would incourge auther to provide detial code examples so that it would become very easy to implement all whatever have been explained. Great work
 
Comment #31  (Posted by an unknown user on 02/12/2008)
Rating
this is useless
 
Sponsored Links