Click here to Skip to main content
Click here to Skip to main content

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"

    WtlGridWrapper      grid;  
    grid.construct();                 //setup
    grid.listener(new LevelListener); //add a listener to overwrite some behavior
    grid.vertical_delimiter(true);  //show vertical lines
    grid.column_header(true); //show header
    grid.toolbar(); //show toolbar
    grid.m_toolbar.AddButton(IDB_NEW,true,"New"); //resource ID and tooltip
    //now add the columns (header,width,alignment,Resource 
    // ID,render mode,edit mode,can grow, can be selected)

   //to add rows, add a vector of cstring
  vector<CString> buf;

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

Comments and Discussions

Generalbug in header PinmemberRiderV30-Dec-10 7:34 
GeneralDisable context menu Pinmemberamarbabu27-Sep-06 8:30 
GeneralDO NOT WRITE YOUR CODE THIS WAY!!! Pinmembermloskot14-Jun-05 13:14 

I really appreciate your (WTL GRID writer) job!
You are a real pioneer of WTL-based grids, but - forgive me - I do not understand how one can write source code this way (as WTL GRID is written).
This code should be given as an example "how to not to write a code"!!!

- no comments - it seems you write your code for yourself
- coding style - your code is not readable at all (bad naming convention, no spaced between function parameters, related members/functions are not put in some blocks, etc.

The most important is that there are no comment of your code. I do not understand what did you generate Doxygen docs for if your code is not commented?!?
As I realized this article (and the code attached) is very old, there is a newer version on your Web Site, but you've not mentioned about the new version in this article.

I know it os Open Source software, you make a big contribution to the Open Source community and developers but your code seems to be usable at all
if developer does not no how to use it. Developer is forced to read and analize your code very carefully but shouldn't. Please, try to feel as you read WTL Grid code for a first time.
Open Source software is ALWAYS well documented and commented.
When you write Open Source write it well or do not publish it at all.
Open Source software should provide as good quality of code.
Simply, I do not understand why CodeProject published it in this poorstate.

I'm not going to attack you. I'm not at all.

Best regards

GeneralRe: DO NOT WRITE YOUR CODE THIS WAY!!! PinmemberNoel Frankinet14-Jun-05 22:29 
GeneralRe: DO NOT WRITE YOUR CODE THIS WAY!!! Pinmembermloskot15-Jun-05 13:51 
GeneralI wanna to put together cells Pinsussi4uman14-Apr-05 21:43 
GeneralPretty code... Pinmembervolmax24-Feb-04 2:57 
General&amp;#65311;&amp;#65311;&amp;#65311; Collapsible tree like behavior. Pinmembernewkey6-Feb-04 21:56 
Generalthis needs work PinmemberEugene Polonsky26-Oct-02 19:41 
GeneralRe: this needs work Pinmemberroel_v6-Mar-03 1:41 
GeneralRe: this needs work Pinmembermloskot14-Jun-05 8:41 
Generalhi ,test PinmemberDeXian2-Jun-02 18:34 
GeneralRe: hi ,test Pinmemberkamal_upreti17-Feb-03 21:09 
GeneralExample source PinmemberKeith Holme29-May-02 3:39 
QuestionWM_MOUSEWHEEL ?? PinmemberDonghun Lee25-Feb-02 19:40 
QuestionAnd how do I get it to show up in a dialog? PinmemberNMTop4011-Feb-02 2:23 
GeneralAnd some major issues PinmemberNMTop407-Feb-02 4:21 
GeneralRe: And some major issues PinmemberNoel Frankinet7-Feb-02 4:37 
GeneralRe: And some major issues PinmemberNMTop407-Feb-02 7:03 
GeneralRe: some major issues in thinking Pinsusssixth_voice1-Oct-03 4:42 
GeneralRe: some major issues in thinking PinmemberMoonlightM27-May-04 4:52 
GeneralA few suggested modifications Pinmemberanonymous26-Feb-02 2:36 
GeneralRe: A few suggested modifications PinsussJusticeMonger31-Oct-03 4:38 
GeneralRedraw problem with example PinmemberRaj_Sidhu1-Feb-02 5:16 
GeneralRe: Redraw problem with example PinmemberNMTop4011-Feb-02 4:25 

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 | Terms of Use | Mobile
Web02 | 2.8.150414.1 | Last Updated 23 Jan 2002
Article Copyright 2001 by Noel Frankinet
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid