53 MEMBERS HAVE RATED THIS ARTICLE. RESULT:
Popularity: 7.54. Rating: 4.38 Out of 5.
Download Demo Project - 15 KB
Introduction
This adds sorting to MFC's list control class Sorting is automatically taken care of:.. It will sort text, dates and numbers in ascending or descending order, and show an arrow in the appropriate direction in the heading for the sorted column It also adds some .
How to use it
Look at the example to see how it is used. You need to add the files SortListCtrl.cpp / h and SortHeaderCtrl.cpp / h to your project, then associate a CSortListCtrl variable with your list control (you can do this with ClassWizard).
In the OnInitDialog member function of your dialog class you set the columns and their initial widths by calling the list control's SetHeadings function, it takes a string, or a string ID in the string table, which defines the column headings and their widths,
E.G.
M_ctllist.setheadings (_t ("name, 120; date of birth, 90; score, 50"));
Adding Rows Is Very Easy, You Call The List Control's Additem Function with the Same Number of strings as the number of columns you added,
E.G.
M_ctllist.additem (_T ("Mark Jackson"), _T ("09/08/1974"), _t ("100"));
To Remember The Column 'Widths Call The Columns' Widths Call The List Control's LoadColumnInfo Function After Setting The Headings, Add A Handler For Your Dialog's WM_DESTROY Message and in There Call SaveColumnInfo.
IMPLEMENTATION
It was a REAL pain to do, your callback function gets the item data for the two rows to compare, but what use is that, you need the text to compare! This control stores the text for the columns in the item data, so the Compare Function Can Get At It, It Also Allows Users of the Control To Use Item Data as Usual.credits
The code for draking the arrow in the header control was write by zafir anjum
Mark Jackson
Click Here to View Mark Jackson's Online Profile.
Other Popular Articles:
XListCtrl -. A custom-draw list control with subitem formattingA custom-draw list control with support for subitem colors, bold font, progress bars, and checkboxes Using the Header ControlAn article describing how to use the header control Neat Stuff to do in List Controls Using Custom DrawUsing the custom-draw features in version 4.70 of the common controls to customise the look and feel of list controls Using the List ControlEverything you need to know about using the standard list control in your app