Click here to Skip to main content
13,045,984 members (45,777 online)
Click here to Skip to main content
Add your own
alternative version


50 bookmarked
Posted 7 Sep 2003

Very useful class to display SQL SELECT results

, 3 Nov 2003
Rate this:
Please Sign up or sign in to vote.
Very useful class to display SQL SELECT results.

Sample screenshot with CListCtrlEx

Fig1. Illustrates CRecordListCtrl based on CListCtrlEx from this article.


In this article, I present a simple CRecordListCtrlM to display the results of a SQL SELECT operation. Why another similar grid control? Yeah, you say, many grids are available for VC++ developers, but this control is small and very useful in MFC applications. Moreover, in combination with CListCtrlEx, presented here.

You will find many advanced unique features for developers and end users. Readers also can replace MFC ODBC classes to MFC DAO. Using ADO or OLE DB classes is also possible.

Sample screenshot with CListCtrl

Fig2. Illustrates CRecordListCtrl based on standard CListCtrl.

In most cases, all that you need to do is call the following:

// aDSN is ODBC datasource name
// aSQL is SQL SELECT query
m_List.LoadListCtrl(CString aDSN, CString aSQL);

How to Use

Using CRecordListCtrl is very simple.

  1. Include the RecordListCtrlEx.h and RecordListCtrlEx.cpp files in your project.
  2. If you want to use CListCtrlEx in this control instead of CListCtrl, just replace with CListCtrlEx.


By reading this article, you receive two variants for using the CRecordListCtrl control. The first is based on CListCtrl, providing an easy-to-use way to display SQL SELECT query results. The second is based on CListCtrlEx, and also makes an easy way possible to show the results of SQL SELECT and provides a lot of end-user-friendly functionality. The functions are:

  • Multicolumn sorting (working as SQL ORDER BY)
  • Multicolumn filtering (working as an additional WHERE section in SQL SELECT)
  • Column data type auto detection (allows the user input to be more friendly)
  • Column coloring and dragging
  • Storing/Loading control state


This software is released into the public domain. You are free to use it in any way you like. You should save the Author text in the header files. If you modify it or extend it, please consider posting new code here for everyone to share. This software is provided "as is" with no expressed or implied warranty. I accept no liability for any damage or loss of business that this software may cause.

My special thanks to other authors.


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

Vitali Halershtein
Software Developer (Senior)
Belarus Belarus
I am a professional Software Developer with more than 10 years' experience.
Certifications: MCSD, MCP, Brainbench, Masters Degree in Computer Science.

I am open for contacts and interesting ideas.
You can write me at:

You may also be interested in...


Comments and Discussions

GeneralMy vote of 4 Pin
Mahdi Nejadsahebi27-Apr-12 19:09
groupMahdi Nejadsahebi27-Apr-12 19:09 
Generalexcellent and simple class with clistctrlex Pin
mjchan16-Feb-05 13:57
membermjchan16-Feb-05 13:57 
GeneralAdjustable Row Height Pin
Umber17-Jun-04 19:47
memberUmber17-Jun-04 19:47 
GeneralRe: Adjustable Row Height [modified] Pin
Vitali Halershtein17-Jun-04 22:40
memberVitali Halershtein17-Jun-04 22:40 
QuestionCan you do it in ATL with no MFC? Pin
1of316-Jun-04 12:24
member1of316-Jun-04 12:24 
AnswerRe: Can you do it in ATL with no MFC? [modified] Pin
Vitali Halershtein17-Jun-04 22:46
memberVitali Halershtein17-Jun-04 22:46 
GeneralCan't compile DemoProject_with_CListCtrlEx Pin
Anonymous22-Apr-04 23:03
sussAnonymous22-Apr-04 23:03 
GeneralRe: Can't compile DemoProject_with_CListCtrlEx [modified] Pin
Vitali Halershtein26-Apr-04 23:59
memberVitali Halershtein26-Apr-04 23:59 
GeneralGreat Work Pin
hfrank28-Dec-03 13:27
memberhfrank28-Dec-03 13:27 
GeneralRe: Great Work [modified] Pin
Vitali Halershtein7-Jan-04 21:51
memberVitali Halershtein7-Jan-04 21:51 
GeneralRe: Great Work Pin
pietro7710-Mar-04 7:30
memberpietro7710-Mar-04 7:30 
QuestionIs it possible??? Pin
cwebiboy9-Dec-03 23:41
membercwebiboy9-Dec-03 23:41 
AnswerRe: Is it possible??? Pin
John M. Drescher10-Dec-03 0:17
memberJohn M. Drescher10-Dec-03 0:17 
AnswerRe: Is it possible??? [modified] Pin
Vitali Halershtein10-Dec-03 0:45
memberVitali Halershtein10-Dec-03 0:45 
GeneralTimeout Pin
Dimitris Vassiliades11-Nov-03 0:29
memberDimitris Vassiliades11-Nov-03 0:29 
GeneralRe: Timeout Pin
Vitali Halershtein12-Nov-03 1:39
memberVitali Halershtein12-Nov-03 1:39 
GeneralParseSQL function Pin
rlieb15-Sep-03 12:15
memberrlieb15-Sep-03 12:15 
GeneralRe: ParseSQL function [modified] Pin
Vitali Halershtein15-Sep-03 20:32
memberVitali Halershtein15-Sep-03 20:32 
GeneralRe: ParseSQL function Pin
rlieb16-Sep-03 3:57
memberrlieb16-Sep-03 3:57 
GeneralRe: ParseSQL function Pin
Mattias G6-Oct-06 1:27
memberMattias G6-Oct-06 1:27 

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.170713.1 | Last Updated 4 Nov 2003
Article Copyright 2003 by Vitali Halershtein
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid