Click here to Skip to main content
11,923,517 members (63,089 online)
Click here to Skip to main content
Add your own
alternative version


51 bookmarked

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

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.151125.3 | Last Updated 4 Nov 2003
Article Copyright 2003 by Vitali Halershtein
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid