C++
  Home arrow C++ arrow Page 2 - A Custom Drawn List Control in C++
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
C++

A Custom Drawn List Control in C++
By: Vitali Halershtein
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 33
    2003-09-13

    Table of Contents:
  • A Custom Drawn List Control in C++
  • The Article
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    A Custom Drawn List Control in C++ - The Article


    (Page 2 of 3 )

    Features

    My new controls class name is ClistCtrlEx. My control contains the following features:

    Multicolumn sorting
    Multicolumn filtering
    Column data type auto detection
    Column coloring and dragging
    Storing/loading control state

    Here’s a quick screenshot of my list control in action:

    1. The first column is sorted in ascending order
    2. The second column is sorted in descending order and is filtered
    3. The third column is simply filtered

    Other features are accessible via the context menu. The context menu can be displayed by right clicking on the columns, as shown below:

    1. Show/hide columns

    1. Automatic find
    2. Automatic filter
    3. Changing sorted columns background color
    4. Reset all settings to default

    The following settings are implemented using the lists control style:

    1. Show/hide gridlines
    2. One click row activation
    3. Column dragging

    The control also allows saving/loading of all of the features above.

    How To Us the Control

    To integrate my list control into your C++ project, here’s what you need to do:

    1. Insert a project into the workspace and setup dependencies from the project -> dependencies menu.
    2. Include the header file ListCtrlEx.h into the necessary files
    3. Add the following definition into your stdafx.h file:

      #define LISTCTRLEXDLL   __declspec( dllimport )

    4. Replace the CListCtrl variable with CListCtrlEx. All methods of the new control have names identical to the same method names of the standard CListCtrl.

    The only exception is the following:

        void BeginTrans();
        void CommitTrans();
        void ApplySettings();
        void LoadSettings();
        void SetIniFileName(CString& sFileName);
        void SetDifferences(int aiCol, BOOL bSearch = TRUE);

    If you want to insert a large number of rows into the control use BeginnTrans() and CommitTrans() before and after the insertion.

    Use SetIniFileName(CString& sFileName) and LoadSettings() to set the full path to the file where the control will store and load its settings from. Call these methods after the controls creation. I.e. If you use a CDialog derived class you can call it from OnInitDialog. For the CFormView derived classes, make this call from OnInitialUpdate.

    Tips and Tricks

    In rare cases you may need to call ApplySettings() to force the control to store its current settings. Now that I’ve described everything you need to know to make my list control work, here’s some sample code:

    CString ini_file = "test.ini";

    m_List.SetIniFileName(ini_file);
    m_List.InsertColumn( 0, "Column 1", LVCFMT_LEFT, 100, 0 );
    m_List.InsertColumn( 1, "Column Numbers", LVCFMT_LEFT, 100, 1 );
    m_List.InsertColumn( 2, "Column Dates", LVCFMT_LEFT, 100, 2 );
    m_List.BeginTrans();

    for(int i=0; i<1000; i++)
    {
        CString txt;
        txt.Format("This is item %d", i);
        int item = m_List.InsertItem( 0, txt );
        txt.Format("%d", i);
        m_List.SetItemText(item, 1, txt);
       
        CTime tm = CTime::GetCurrentTime();
        m_List.SetItemText(item, 2, tm.Format("%d/%m/%Y"));
    }

    m_List.CommitTrans();

    Usage
    This software is released into the public domain. You are free to use it in any way you like. You should keep my author text in the header files. If you modify or extend my control, please consider posting the new code here in the DevArticles forum 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.

    More C++ Articles
    More By Vitali Halershtein


     

    C++ ARTICLES

    - Multiplying Large Numbers with Karatsuba`s A...
    - Large Numbers
    - Dijkstra`s Shunting Algorithm with STL and C...
    - Brief Introduction to the STL Containers
    - The Standard Template Library
    - Templates in C++
    - C++ Programmer Alerts
    - C++ Programming Tips
    - First Steps in (C) Programming, conclusion
    - First Steps in (C) Programming, continued
    - First Steps in (C) Programming, introduction
    - C++ Preprocessor: Always Assert Your Code Is...
    - C++ Preprocessor: The Code in the Middle
    - Programming in C
    - Temporary Variables: Runtime rvalue Detection






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
    Stay green...Green IT