Click here to Skip to main content
13,048,406 members (149,165 online)
Click here to Skip to main content
Add your own
alternative version


9 bookmarked
Posted 27 May 2014

Color Block Overlay for DataGridView

, 27 May 2014
Rate this:
Please Sign up or sign in to vote.
This component allows to overlay grid with colored blocks spanning across multiple columns.

control screenshot


This component allows to overlay grid with colored blocks spanning across multiple columns. Color block is bound to a particular row through unique id and it is possible to resize/move these blocks. Hope this helps someone having similar requirements.

Implemented features are listed below:

  • select
  • resize: ability to validate resize operation + ColorBlockResized event with cancel support
  • drag & drop: Per-cell granularity to allow/deny drop + ColorBlockMoved event with cancel support
  • color blocks can overlap: Color block with biggest starting column will be drawn on top
  • color blocks with colspan bigger than available area on grid
  • text in color block
  • scrolling with frozen columns
  • sort/group operations of the underlying grid
  • resizing columns
  • image at the beginning of the block

Using the Code

As I prefer pictures more than text or code, let me begin with a diagram showing the component organization:

Overlay component is abstracted from the grid therefore, providing you can implement IOverlaidGrid interface which is the contact point with underlying grid, it is possible to integrate it with any grid. Originally, it was developed to use over different grid and only for the purpose of this tip, it was integrated with the standard .NET DataGridView. Integration of component can be done through inheritance or composition, in demo inheritance is used - DataGridViewEx. Main class handling color block rendering is GridOverlayRenderer. This class needs a reference to object implementing IOverlaidGrid and to control over which drawing is performed. It provides Render method which renders configured color blocks. In the example, this method is called in Paint event of DataGridViewEx. Color blocks can be configured via InitializeOverlay method of GridOverlayRenderer - see OnLoad in Form1. For further details, please refer to the attached source code.


In the tip, I used the work of others. Here are references to the original articles:


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


About the Author

Matus Kovacik
Software Developer
Slovakia Slovakia
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionThanks and question Pin
Member 1200812825-Apr-17 22:46
memberMember 1200812825-Apr-17 22:46 
QuestionThank You Pin
Member 1131388215-Jun-15 23:21
memberMember 1131388215-Jun-15 23:21 
QuestionNice! Pin
Volynsky Alex28-May-14 0:23
professionalVolynsky Alex28-May-14 0:23 
AnswerRe: Nice! Pin
Matus Kovacik28-May-14 7:50
memberMatus Kovacik28-May-14 7:50 
QuestionRe: Nice! Pin
Volynsky Alex28-May-14 8:20
professionalVolynsky Alex28-May-14 8:20 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170713.1 | Last Updated 27 May 2014
Article Copyright 2014 by Matus Kovacik
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid