Click here to Skip to main content
Click here to Skip to main content
Go to top

C# Grid

, 11 Dec 2003
Rate this:
Please Sign up or sign in to vote.
An implementation of a grid in C#


Before we begin, this grid is in it's infancy and I hope with collaboration from other CodeProject members we can make this grid as functional as the one you would find in Microsoft Excel, in respect of that I've kept the article content to a minimum, expect it grow in the coming months.

Expect bugs and lack of functionality these items will be addressed in future releases.

What's missing:

  • Image alignment in cells
  • Limited events
  • Specialized Cells
  • A whole raft of other stuff

If you would like to contribute to this project, email me using the discussion thread below. I'm looking really for 2 other people who would have good GUI and design skills.


The grid is primary to be used as a control and could be optionally used a straight class. Lets take a look at a simplistic class design.

I've excluded properties and methods here, these will be documented at a later stage.

Example of use

virtual public void Demo()

    gridCtrl.LockUpdates = true;

    for (int r=0; r < 30; r++)

    for (int c=0; c < 30; c++)

    int ii=0;

    int i=255;
    for (int r=1;r < gridCtrl.rowList.Count;r++)
        i = 255;
        for (int c=1;c < gridCtrl.colList.Count;c++)
            gridCtrl.GetCell(r,c).Value = ii++;
            gridCtrl.GetCell(r,c).BackColor = Color.FromArgb(i,i,255);;


    gridCtrl.GetRow(2).Size = 40;
    gridCtrl.GetColumn(1).Size = 180; 
    gridCtrl.GetRow(8).Visible = false;

    gridCtrl.GetRow(17).Size = 40;

    gridCtrl.GetCell(1,4).BackColor = Color.Cornsilk;
    gridCtrl.GetCell(2,4).BackColor = Color.CornflowerBlue;
    gridCtrl.GetCell(3,4).BackColor = Color.Coral;
    gridCtrl.GetCell(4,4).BackColor = Color.CadetBlue;

    gridCtrl.GetCell(1,1).HorizontalAlignment = 
    gridCtrl.GetCell(1,1).Value = "Left";
    gridCtrl.GetCell(1,1).TextColor = Color.Blue;
    gridCtrl.GetCell(1,1).FontName = "System";

    gridCtrl.GetCell(2,1).HorizontalAlignment = 
    gridCtrl.GetCell(2,1).Value = "Center";
    gridCtrl.GetCell(3,1).HorizontalAlignment =
    gridCtrl.GetCell(3,1).Value = "Right";

    gridCtrl.GetCell(4,1).VerticalAlignment = 
    gridCtrl.GetCell(4,1).Value = "Top";
    gridCtrl.GetCell(5,1).VerticalAlignment = 
    gridCtrl.GetCell(5,1).Value = "Center";
    gridCtrl.GetCell(6,1).VerticalAlignment = 
    gridCtrl.GetCell(6,1).Value = "Bottom";

    gridCtrl.GetCell(2,2).FontStyle = FontStyle.Bold;
    gridCtrl.GetCell(2,3).FontStyle = FontStyle.Italic;
    gridCtrl.GetCell(2,4).FontStyle = FontStyle.Underline;
    gridCtrl.GetCell(12,12).TipText = "Cell";

    Cell cell = gridCtrl.GetCell(7,1);
    cell.TextColor = Color.Yellow;
    cell.BackColor = Color.Black;
    cell.Value = "Funny";

    gridCtrl.GetRow(4).CanResize = false;
    gridCtrl.GetColumn(4).CanResize = false;

    gridCtrl.GetCell(9,1).FontName = "Wingdings";
    gridCtrl.GetCell(17,1).Image = new Bitmap(GetType(), "image1.bmp");

    gridCtrl.LockUpdates = false;


  • 1.0 - 12 September 2003 - Initial Release.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Software Developer (Senior) Software Kinetics
United Kingdom United Kingdom

Software Kinetics
are experts in developing customised and bespoke applications and have expertise in the development of desktop, mobile and internet applications on Windows.

We specialise in:

  • User Interface Design
  • Desktop Development
  • Windows Phone Development
  • Windows Presentation Framework
  • Windows Forms
  • Windows Communication Framework
  • Windows Services
  • Network Applications
  • Database Applications
  • Web Development
  • Web Services
  • Silverlight
Visit Software Kinetics
Follow on   Twitter

Comments and Discussions

GeneralMy vote of 5 Pinmemberr_pippi22-Mar-11 5:01 
GeneralMy vote of 1 PinmemberRyleigh27-Mar-09 7:40 
GeneralRe: My vote of 1 PingroupNorm .net20-May-09 4:43 
Questionchange name of headers Pinmemberamrsoft12324-Mar-09 23:57 
Generalhardcoded paths PinmemberKen Mazaika26-Sep-07 5:00 
Generalsmall bug PinmemberPramod Sivanandan26-Dec-06 23:21 
GeneralDisplaying data in grid PinmemberGreg Schroder15-Jul-04 8:25 
GeneralRe: Displaying data in grid PinmemberTim Kohler15-Jul-04 8:54 
GeneralRe: Displaying data in grid PinmemberMike Osbahr15-Jul-04 9:37 
GeneralTextHeight Property Pinmemberandyj18329-Jun-04 3:49 
GeneralRe: TextHeight Property Pinmembernorm.net22-Jun-04 4:21 
GeneralVirtual Grid Architecture PinsussAnonymous9-Jan-04 5:42 
GeneralRe: Virtual Grid Architecture PinmemberNorm Almond12-Mar-04 0:19 
QuestionHow to Make it Redraw a Cell PinmemberSudhir Bhat31-Dec-03 2:04 
AnswerRe: How to Make it Redraw a Cell PinmemberNorm Almond31-Dec-03 5:39 
Generaluser control PinmembernavyC527-Dec-03 12:48 
GeneralRe: user control PinsussAnonymous30-Dec-03 14:07 
QuestionHow to modify the header ? PinmemberThierry Parent16-Dec-03 1:32 
AnswerRe: How to modify the header ? PinmemberNormski25-Dec-03 1:56 
QuestionRe: How to modify the header ? Pinmemberamrsoft12324-Mar-09 23:57 
GeneralRightToLeft PinsussAnonymous15-Dec-03 20:30 
GeneralWinForms DataGrid Sort Indicator Pinmemberkkaps15-Dec-03 11:10 
Generalsuggestion: complex headers Pinmemberbluemiracoli15-Dec-03 3:47 
Generalsuggestion: complex headers Pinmemberbluemiracoli15-Dec-03 3:37 
GeneralSmall bug PinmemberThierry Parent14-Dec-03 22:11 
GeneralFeature plan PinmemberBill Seddon12-Dec-03 8:25 
GeneralRe: Feature plan PinmemberNormski12-Dec-03 10:43 
GeneralSuggestion PinmemberJörgen Sigvardsson12-Dec-03 5:44 
GeneralRe: Suggestion PinmemberNormski12-Dec-03 6:23 
GeneralVirtual Grid Pinmemberrfmobile12-Dec-03 3:37 
GeneralRe: Virtual Grid PinmemberNormski12-Dec-03 3:59 
GeneralRe: Virtual Grid PinmemberKeith Farmer12-Dec-03 16:07 
QuestionShould we contribute....? Pinmembermogwai12-Dec-03 3:26 
AnswerRe: Should we contribute....? PinmemberNormski12-Dec-03 3:57 
GeneralRe: Should we contribute....? Pinmembermogwai12-Dec-03 4:41 
GeneralRe: Should we contribute....? PinmemberNormski12-Dec-03 4:47 

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.

| Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 12 Dec 2003
Article Copyright 2003 by NormDroid
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid