Click here to Skip to main content
15,881,204 members
Articles / Programming Languages / SQL

Outlook Style DataGrid

Rate me:
Please Sign up or sign in to vote.
1.10/5 (14 votes)
21 Mar 2006CPOL2 min read 135.4K   2.7K   73   17
Easy way to create an Outlook style DataGrid.

Sample Image

Introduction

In this implementation, I have tried to create an Outlook style DataGrid which has expand/collapse functionality. There are several custom controls available in the market which have rich Outlook type grid functionality. What I am trying to do here is to illustrate specifically the Expand/Collapse functionality with the new DataGridView control that comes with .NET 2.0.

Background

The control that Outlook uses is a SuperGrid which is not exposed for developers with .NET 2.0 controls. I have used events like dataGridView1_RowsAdded, dataGridView1_CellContentClick to illustrate how this functionality can be achieved easily using the DataGridView control. The idea is to achieve a Master and Detail view of the data. Master details will be displayed by default; on expanding a Master row, the corresponding details rows will be populated.

Using the Code

The code uses the Northwind database that comes by default with SQL Server. Visual Studio 2005 needs to be used to get the DataGridView control.

This code uses two Stored Procedures for getting the Master/Detail from the database. This one returns the unique CustomerID from the Orders table:

SQL
CREATE procedure OrderMaster
as
select     distinct CUSTOMERID
from     ORDERS
ORDER BY CUSTOMERID 
GO

Create another Stored Procedure that takes the customer ID as a parameter and returns the matching order details from the same Orders table.

SQL
CREATE procedure GetCustomerDetails
@customerId varchar(50) 
as 
select OrderID, ShipName, ShipAddress
from orders where customerid= @customerId
GO

Points of Interest

The idea behind simulating this behavior is using three images: "PLUS", "MINUS", and "BLANK". The first column in the grid is a DataGridViewImageColumn. The other columns are used to display data. I have not used any bound column. With further research, bound columns can also be used. Initially, only the master details are displayed, with the first column image as "PLUS". On clicking on PLUS, the image changes to MINUS and the tag property is passed as the CustomerID to get the details. Once it gets the details, it inserts rows next to the current row. Clicking on the first column again removes those rows from the grid.

History

I had a requirement to implement this functionality. I searched a lot, but could not find any easy solution. My requirement was just to add Expand/Collapse functionality, and so I decided to implement just this. Hope it is helpful to you guys.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
BugDoesn't work on windows 8.1 visual studio 2012. Pin
Aleksandras Teniuch21-May-15 0:56
Aleksandras Teniuch21-May-15 0:56 
GeneralLayout (cell size) of detail rows Pin
SeBEssaWissa19-May-10 11:51
SeBEssaWissa19-May-10 11:51 
GeneralWhy not DataGrid 2.0 Pin
Syed Mehroz Alam2-Mar-07 2:09
Syed Mehroz Alam2-Mar-07 2:09 
GeneralRe: Why not DataGrid 2.0 Pin
Emmanuel Process27-Aug-08 6:47
Emmanuel Process27-Aug-08 6:47 
GeneralRe: Why not DataGrid 2.0 Pin
Syed Mehroz Alam27-Aug-08 18:26
Syed Mehroz Alam27-Aug-08 18:26 
GeneralMissing Stored Proc Pin
rjb227s24-Jul-06 19:01
rjb227s24-Jul-06 19:01 
GeneralRe: Missing Stored Proc [modified] Pin
Stellar Developer16-Nov-06 5:35
Stellar Developer16-Nov-06 5:35 
GeneralLast Row Bug [modified] Pin
mavilym12-Jul-06 3:45
mavilym12-Jul-06 3:45 
GeneralRe: Last Row Bug Pin
mavilym12-Jul-06 4:06
mavilym12-Jul-06 4:06 
Jokeerror when try to click on the text of the header Pin
dops20-Apr-06 4:30
dops20-Apr-06 4:30 
JokeRe: error when try to click on the text of the header Pin
dops20-Apr-06 4:52
dops20-Apr-06 4:52 
Generalimage and code missing Pin
kleinecools21-Mar-06 21:25
kleinecools21-Mar-06 21:25 
GeneralRe: image and code missing Pin
Prithvis22-Mar-06 3:20
Prithvis22-Mar-06 3:20 
QuestionCode and Image ?? Pin
AxelM21-Mar-06 20:46
AxelM21-Mar-06 20:46 
AnswerRe: Code and Image ?? Pin
Prithvis22-Mar-06 3:35
Prithvis22-Mar-06 3:35 
Generalfile and image Pin
HRiazi21-Mar-06 8:37
HRiazi21-Mar-06 8:37 
Hi;

Where is the file and the image to your article?!
Could you kindly fix it.

Thanks
Hadi
QuestionWhere is the image ???? Pin
Patrick Antonioli Ferraro21-Mar-06 8:29
Patrick Antonioli Ferraro21-Mar-06 8:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.