A Very Useful Class to Display SQL SELECT Results

Figure 1. Illustrate CRecordListCtrl based on standard CListCtrl.

Introduction

In this article, I present a simple CRecordListCtrl 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 at http://www.creative-case.com/articles/ClistctrlEx.htm, 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. Moreover, a demo for CListCtrlEx virtual grid control targeted for a large amount of data was published in September of 2004 http://www.creative-case.com/articles/ClistctrlEx.htm.

Figure 2. Illustrate CRecordListCtrl based on CListCtrlEx.

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 the Control

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 CListCtrl 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 go to the other authors.

Downloads

Download source code - 3 Kb
Download demo project - 186 Kb


About the Author

Vitali Halershtein

I'm 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: vitali_eh@yahoo.com

Comments

  • The link for the CListCtrlEx doesn't exist.

    Posted by malfaro on 04/22/2008 07:27pm

    The URL: http://www.creative-case.com/articles/ClistctrlEx.htm doesn't exist anymore. please send me the project files and the article. My mail is mauricioalfaro@telesal.net

    Reply
  • Help!!! I need the ListCtrlEx.h to compile

    Posted by fgmproxy on 12/20/2004 01:19am

    I think you have done a good job, I like the function you code bring to us!!!

    • This article presents CRecordListCtrl class

      Posted by Vitali on 12/20/2004 03:35am

      This article presents CRecordListCtrl. Please read appropriate article at the: http://www.creative-case.com/articles/ClistctrlEx.htm for CListCtrlEx usage.

      Reply
    Reply
  • Where Can I Find 'ListCtrlEx.h'???????

    Posted by smaak on 07/09/2004 04:55am

    I'm not able to compile the demo project and I know that the file 'ListCtrlEx.h' is missing. Can you include the 'ListCtrlEx.h' with the project?
    
    Smaak

    • This article presents CRecordListCtrl class

      Posted by Vitali on 07/09/2004 06:28am

      Dear smaak,

      please carefully read Usage section of the articleabout CListCtrlEx at the URL: http://www.creative-case.com/articles/ClistctrlEx.htm

      With best wishes,
      Vitali Halershtein

      Reply
    Reply
  • Adjustable Row Height as in Flex Grid

    Posted by ushamim on 06/17/2004 04:10am

    It was very interesting to see all the enhancements you have done in the CListCtrl but actually i was wondering if there is any way we can add the adjustable row height funtionality of a grid control into the CListCtrl

    • not in current version - height can be changed only for all rows once

      Posted by Vitali on 06/17/2004 10:20am

      In the current version only all rows height can be changed by setting imagelist on the list control. Just set up the imagelist with image 1 pixel width and neccessary height on the list control to do this.

      Reply
    Reply
  • Thanks

    Posted by Legacy on 10/01/2003 12:00am

    Originally posted by: Just Developer

    Thanks for the code. It really useful.

    • Where Can I Find 'ListCtrlEx.h'???????

      Posted by smaak on 07/08/2004 08:34am

      I'm not able to compile the demo project and I know that the file 'ListCtrlEx.h' is missing. Can you include the 'ListCtrlEx.h' with the project?
      
      Smaak

      Reply
    • Great But you could include 'ListCtrlEx.h'

      Posted by blueneon on 03/19/2004 06:40am

      Great but the CListViewEx version dosnt compile
      im sure you know about this but...

      
      // This is include to CListCtrlEx from:
      #include "d:\\ListCtrlEx\\Inc\\ListCtrlEx.h" 
      // Please type correct path here
      

      this line causes the project not to compile. Can you include the 'ListCtrlEx.h' with the project. Alex

      Reply
    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: September 10, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild". This loop of continuous delivery and continuous feedback is …

  • The explosion in mobile devices and applications has generated a great deal of interest in APIs. Today's businesses are under increased pressure to make it easy to build apps, supply tools to help developers work more quickly, and deploy operational analytics so they can track users, developers, application performance, and more. Apigee Edge provides comprehensive API delivery tools and both operational and business-level analytics in an integrated platform. It is available as on-premise software or through …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds