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:
The first column is sorted in ascending order
The second column is sorted in descending order and is filtered
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:
Show/hide columns
Automatic find
Automatic filter
Changing sorted columns background color
Reset all settings to default
The following settings are implemented using the lists control style:
Show/hide gridlines
One click row activation
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:
Insert a project into the workspace and setup dependencies from the project -> dependencies menu.
Include the header file ListCtrlEx.h into the necessary files
Add the following definition into your stdafx.h file:
#define LISTCTRLEXDLL __declspec( dllimport )
Replace the CListCtrl variable with CListCtrlEx. All methods of the new control have names identical to the same method names of the standard CListCtrl.
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:
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.