Click here to Skip to main content
15,881,588 members
Articles / Desktop Programming / MFC
Article

Very useful class to display SQL SELECT results

Rate me:
Please Sign up or sign in to vote.
4.49/5 (42 votes)
3 Nov 20032 min read 93.4K   5.1K   50   20
Very useful class to display SQL SELECT results.

Sample screenshot with CListCtrlEx

Fig1. Illustrates CRecordListCtrl based on CListCtrlEx from this article.

Introduction

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.

Conclusion

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

Usage

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.

License

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


Written By
Software Developer (Senior)
Europe Europe
I am a professional Software Developer with more than 20 years' experience.

I am open for contacts and interesting ideas.
You can write me at:
vitali_eh@yahoo.com

Comments and Discussions

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