Click here to Skip to main content
Licence CPOL
First Posted 21 Mar 2006
Views 77,351
Downloads 1,033
Bookmarked 69 times

Outlook Style DataGrid

By | 21 Mar 2006 | Article
Easy way to create an Outlook style DataGrid.
 
Part of The SQL Zone sponsored by
See Also

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:

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.

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)

About the Author

Prithvis

Web Developer

United States United States

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralLayout (cell size) of detail rows PinmemberSeBEssaWissa11:51 19 May '10  
GeneralWhy not DataGrid 2.0 PinmemberSyed Mehroz Alam2:09 2 Mar '07  
GeneralRe: Why not DataGrid 2.0 PinmemberEmmanuel Process6:47 27 Aug '08  
GeneralRe: Why not DataGrid 2.0 PinmemberSyed Mehroz Alam18:26 27 Aug '08  
GeneralMissing Stored Proc Pinmemberrjb227s19:01 24 Jul '06  
GeneralRe: Missing Stored Proc [modified] PinmemberStellar Developer5:35 16 Nov '06  
GeneralLast Row Bug [modified] Pinmembermavilym3:45 12 Jul '06  
GeneralRe: Last Row Bug Pinmembermavilym4:06 12 Jul '06  
Jokeerror when try to click on the text of the header Pinmemberdops4:30 20 Apr '06  
JokeRe: error when try to click on the text of the header Pinmemberdops4:52 20 Apr '06  
Generalimage and code missing Pinmemberkleinecools21:25 21 Mar '06  
GeneralRe: image and code missing PinmemberPrithvis3:20 22 Mar '06  
QuestionCode and Image ?? PinmemberAxelM20:46 21 Mar '06  
AnswerRe: Code and Image ?? PinmemberPrithvis3:35 22 Mar '06  
Generalfile and image PinmemberH.Riazi8:37 21 Mar '06  
QuestionWhere is the image ???? PinmemberPatrick Antonioli8:29 21 Mar '06  

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

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 21 Mar 2006
Article Copyright 2006 by Prithvis
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid