Click here to Skip to main content
15,886,012 members
Articles / Programming Languages / C++

CGrid Control

Rate me:
Please Sign up or sign in to vote.
4.14/5 (18 votes)
8 May 2007CPOL1 min read 68.6K   5.2K   48   11
An article on a grid control built with Windows API. Also includes an MFC class
Screenshot - mfc.jpg

Introduction

This article presents a Grid control which is built with Windows API. It also has an MFC class.

Background

You can get many grid controls from the Internet. Maybe some of them are free and others are not. Grid is a useful control to show or edit data. The grid control presented in this article support up to 65536 rows and 256 columns. It also supports text edit and boolean type edit.

Using the Code

To use the Grid control in SDK project, grid_lib project must be compiled. And after that, a header file must be included.

C++
#include "grid_lib\grid_lib.h"

Next, initialize the Grid and create a window handle of the Grid.

C++
InitGrid(::GetModuleHandle(NULL));
hWndGrid = CreateGrid(WS_VISIBLE | WS_CHILD, 0, 0, 0, 0, hWnd, ::GetModuleHandle(NULL));

To use the Grid control in MFC project, grid_lib project must be compiled. And after that, a header file must be included.

C++
#include "MFCGrid.h"

After creating an instance of grid control, use GetGrid() function to get the CGrid* pointer. The CGrid control supports the following:

  • CellFromPoint
  • ClearCell
  • Draw
  • Get background brush
  • Get/set background color
  • Get/set fix cell background color
  • Get/set fix cell board color
  • Get/set focus cell board color
  • Get/set selected cell background color
  • Get/set sheet background color
  • Get/set column count
  • Get/set row count
  • Get/set fix row count
  • Get/set fix column count
  • Get/set font
  • GetMergeInfo
  • Get/set row height
  • Get/set column width
  • Insert/remove row
  • Insert/remove column
  • Merge/split cells
  • Get/set cell text
  • Get/set cell char
  • Get/set cell uchar
  • Get/set cell short
  • Get/set cell ushort
  • Get/set cell int
  • Get/set cell uint
  • Get/set cell long
  • Get/set cell ulong
  • Get/set cell float
  • Get/set cell double
  • Get/set cell bool

History

  • 29/05/2007: First release

License

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


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

Comments and Discussions

 
QuestionGreat work! Pin
nilaysoft7-Aug-17 20:57
nilaysoft7-Aug-17 20:57 
GeneralMy vote of 5 Pin
nanosgr27-Dec-11 4:54
nanosgr27-Dec-11 4:54 
GeneralA Little Bug Pin
Mycro3-Aug-10 23:14
Mycro3-Aug-10 23:14 
AnswerRe: A Little Bug Pin
duck5tar3-May-13 0:28
duck5tar3-May-13 0:28 
GeneralCool... but.. Pin
Jackie Roh25-Oct-07 21:43
Jackie Roh25-Oct-07 21:43 
Generalso few columns Pin
ForTheWind1-Jul-07 23:39
ForTheWind1-Jul-07 23:39 
GeneralExcellent! Just one feature request....! [modified] Pin
G A McHale15-May-07 19:45
G A McHale15-May-07 19:45 
Very very useful. I want to avoid MFC dependencies, but still need to code in C++ at the moment. As a Win32 control this will be relatively easily to use in other technologies without adding additional dependencies.

My feature request is just one thing. When you select multiple entries, and then do a copy and paste, only the first entry is copied. Spreadsheets are great for editing large amounts of data quickly. This is seriously compromised by not being able to do multiple copies.

Anyway.. thanks for a useful (fast and simple) control!

Gary



-- modified at 3:03 Wednesday 16th May, 2007
GeneralNice work, but... Pin
Kochise8-May-07 23:25
Kochise8-May-07 23:25 
GeneralRe: Nice work, but... Pin
Henry Venn9-May-07 15:54
Henry Venn9-May-07 15:54 
GeneralRe: Nice work, but... Pin
Charlie, Wang9-May-07 16:47
Charlie, Wang9-May-07 16:47 
GeneralRe: Nice work, but... Pin
Kochise9-May-07 21:26
Kochise9-May-07 21:26 

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.