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

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:

Comments and Discussions

GeneralMy vote of 4 PingroupMahdi Nejadsahebi27-Apr-12 19:09 
Generalexcellent and simple class with clistctrlex Pinmembermjchan16-Feb-05 13:57 
GeneralAdjustable Row Height PinmemberUmber17-Jun-04 19:47 
GeneralRe: Adjustable Row Height [modified] PinmemberVitali Halershtein17-Jun-04 22:40 
QuestionCan you do it in ATL with no MFC? Pinmember1of316-Jun-04 12:24 
AnswerRe: Can you do it in ATL with no MFC? [modified] PinmemberVitali Halershtein17-Jun-04 22:46 
GeneralCan't compile DemoProject_with_CListCtrlEx PinsussAnonymous22-Apr-04 23:03 
GeneralRe: Can't compile DemoProject_with_CListCtrlEx [modified] PinmemberVitali Halershtein26-Apr-04 23:59 
GeneralGreat Work Pinmemberhfrank28-Dec-03 13:27 
GeneralRe: Great Work [modified] PinmemberVitali Halershtein7-Jan-04 21:51 
GeneralRe: Great Work Pinmemberpietro7710-Mar-04 7:30 
QuestionIs it possible??? Pinmembercwebiboy9-Dec-03 23:41 
AnswerRe: Is it possible??? PinmemberJohn M. Drescher10-Dec-03 0:17 
AnswerRe: Is it possible??? [modified] PinmemberVitali Halershtein10-Dec-03 0:45 
GeneralTimeout PinmemberDimitris Vassiliades11-Nov-03 0:29 
GeneralRe: Timeout PinmemberVitali Halershtein12-Nov-03 1:39 
GeneralParseSQL function Pinmemberrlieb15-Sep-03 12:15 
GeneralRe: ParseSQL function [modified] PinmemberVitali Halershtein15-Sep-03 20:32 
GeneralRe: ParseSQL function Pinmemberrlieb16-Sep-03 3:57 
GeneralRe: ParseSQL function PinmemberMattias G6-Oct-06 1:27 

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 | Mobile
Web01 | 2.8.140721.1 | Last Updated 4 Nov 2003
Article Copyright 2003 by Vitali Halershtein
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid