Click here to Skip to main content
12,824,787 members (38,290 online)
Click here to Skip to main content
Add your own
alternative version


52 bookmarked
Posted 7 Oct 2001

A WTL Grid

, 22 Jan 2002
Rate this:
Please Sign up or sign in to vote.
A WTL grid (really).

Sample Image - WtlGrid.gif


After using WTL for some time, I've developed the control that I miss the most for the kind of project that I do : A grid.
This one is written from scratch, derived from a CScrollWindowImpl, it has the following features :

  • Grid is a vector of vector of CString.
  • It has a optional Toolbar where to add buttons with tooltip for edition operation (see screenshot).
  • Resizable column title
  • In place edit using a edit box, a combo box or a check-box.
  • Collapsible tree like behavior.
  • Overwritable behavior (BeforeEdit, AfterEdit, CellRendering, etc) via a derivable listener class.
Using it should be pretty straightforward:
#include <span class="code-string">"WtlGrid.h"</span>

The inner code is also designed to be easy to understand, you'll find the following classes :


a cell value, stored as a CString.


a cell with a render mode.


a column, with header, etc.


a column collection, a vector of column.


a grid row, holding a vector of WtlGridCell.


a collection of rows.


the control itself, containing columns and rows.


a wrapper control for the toolbar and the column header, this is the control that you include in your app.

Some behavior, especially the way cell are rendered and edited can be changed by overwriting a listener class, eg:

class LevelListener : public WtlGridListener 
 public : 

  virtual bool after_edit(WtlGrid *grid, CString &old_value, 
                          int row_nb, int column_nb,void *user,bool add);
  virtual bool after_select(WtlGrid *grid,int row_nb,int column_nb,void *user);
  virtual bool toolbar_button(WtlGrid *grid,int button_nb,void *user);
  virtual bool header_select(WtlGrid *grid,int header_nb,void *user);
  virtual bool render(WtlGrid *grid,CDCHandle dc, CRect &rc,
                      WtlGridRow *row,WtlGridCell *cell,void *user);
  virtual WtlGridColumn::e_edit_mode before_edit(WtlGrid *grid,
                                                 int row_nb, int column_nb,
                                                 void *user);

What is missing:

  • Obviously, the grid should be bindable to a database, and do it virtually (not loading all the records in memory), this will be my next move.
  • A lot of features...
I would be grateful to get comments and enhancement to this code, enjoy ...


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

Noel Frankinet
Architect strategis
Belgium Belgium
No Biography provided

You may also be interested in...

Comments and Discussions

Generalbug in header Pin
RiderV30-Dec-10 7:34
memberRiderV30-Dec-10 7:34 
GeneralDisable context menu Pin
amarbabu27-Sep-06 8:30
memberamarbabu27-Sep-06 8:30 
mloskot14-Jun-05 13:14
membermloskot14-Jun-05 13:14 
Noel Frankinet14-Jun-05 22:29
memberNoel Frankinet14-Jun-05 22:29 
mloskot15-Jun-05 13:51
membermloskot15-Jun-05 13:51 
GeneralI wanna to put together cells Pin
i4uman14-Apr-05 21:43
sussi4uman14-Apr-05 21:43 
GeneralPretty code... Pin
volmax24-Feb-04 2:57
membervolmax24-Feb-04 2:57 
General&amp;#65311;&amp;#65311;&amp;#65311; Collapsible tree like behavior. Pin
newkey6-Feb-04 21:56
membernewkey6-Feb-04 21:56 
Generalthis needs work Pin
Eugene Polonsky26-Oct-02 19:41
memberEugene Polonsky26-Oct-02 19:41 
GeneralRe: this needs work Pin
roel_v6-Mar-03 1:41
memberroel_v6-Mar-03 1:41 
GeneralRe: this needs work Pin
mloskot14-Jun-05 8:41
membermloskot14-Jun-05 8:41 
Generalhi ,test Pin
DeXian2-Jun-02 18:34
memberDeXian2-Jun-02 18:34 
GeneralRe: hi ,test Pin
kamal_upreti17-Feb-03 21:09
memberkamal_upreti17-Feb-03 21:09 
GeneralExample source Pin
Keith Holme29-May-02 3:39
memberKeith Holme29-May-02 3:39 
QuestionWM_MOUSEWHEEL ?? Pin
Donghun Lee25-Feb-02 19:40
memberDonghun Lee25-Feb-02 19:40 
QuestionAnd how do I get it to show up in a dialog? Pin
NMTop4011-Feb-02 2:23
memberNMTop4011-Feb-02 2:23 
GeneralAnd some major issues Pin
NMTop407-Feb-02 4:21
memberNMTop407-Feb-02 4:21 
Ok, now for some serious issues.

It is not a good idea in STL to store collections of editable objects.

Why? Because in order to change them you have to return pointers or non-const references to the actual elements in the STL collection. That is fine if the collection will always remain static, but in this case it is flexible.

If any row or column is added or deleted anywhere, all your pointers could become invalidated. In addition it is quite expensive as you are copying collections time and again.

What you should use is an array of smart (reference-counting) pointers. To do that your row column and cell/value classes should contain their own reference count and your collections will be of these smart pointers. (There are various smart-pointer templates available. I use my own, but you can get them at boost and possibly at this site).

Incidentally, I changed the WtlGridCell class to be derived from WtlGridValue rather than contain it, as it exposed an identical interface extended.

I also made the listener pointer a smart pointer within the WtlGrid class. (I cannot give you my actual code changes without getting permission).
GeneralRe: And some major issues Pin
Noel Frankinet7-Feb-02 4:37
memberNoel Frankinet7-Feb-02 4:37 
GeneralRe: And some major issues Pin
NMTop407-Feb-02 7:03
memberNMTop407-Feb-02 7:03 
GeneralRe: some major issues in thinking Pin
sixth_voice1-Oct-03 4:42
susssixth_voice1-Oct-03 4:42 
GeneralRe: some major issues in thinking Pin
MoonlightM27-May-04 4:52
memberMoonlightM27-May-04 4:52 
GeneralA few suggested modifications Pin
anonymous26-Feb-02 2:36
memberanonymous26-Feb-02 2:36 
GeneralRe: A few suggested modifications Pin
JusticeMonger31-Oct-03 4:38
sussJusticeMonger31-Oct-03 4:38 
GeneralRedraw problem with example Pin
Raj_Sidhu1-Feb-02 5:16
memberRaj_Sidhu1-Feb-02 5:16 
GeneralRe: Redraw problem with example Pin
NMTop4011-Feb-02 4:25
memberNMTop4011-Feb-02 4:25 

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
Web02 | 2.8.170308.1 | Last Updated 23 Jan 2002
Article Copyright 2001 by Noel Frankinet
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid