Implementing Alphanumeric Ordering

Copyright © 2008 by David Wincelberg

I made some changes to the source code described in my October 2000 Dr. Dobb's Journal article in response to suggestions from a reader. Click for the revised source code. This source code and the samples below may be used in any programs, including commercial ones.

MFC Controls Samples (Visual C++ 6.0)

CListBox and CComboBox

In the following image, the list box on the right uses owner drawing to allow for replacing the sorting order with an alphanumeric one. Note that the text looks the same as that on the left, which is an ordinary list box with alphabetic sorting activated. My attempt to create an owner-draw combo box was not totally successful. Instead, I implemented a combo box that uses simple alphanumeric ordering to decide where to place entries.

SortTest application showing different sort orders

Downloads

SortTest.zip (80 KB)
This contains the project files, including those for the modified list and combo boxes.

SortListBox.zip (8 KB)
This is an owner-draw list box with simple alphanumeric ordering and handling of horizontal extent.
Styles selected: owner-draw variable, sort, horizontal scroll, vertical scroll
Style not selected: has strings

SortComboBox.zip (7 KB)
This is an owner-draw combo box with simple alphanumeric ordering.
Styles selected: owner-draw variable, sort, vertical scroll
Style not selected: has strings
Problem: Dropping down the list box when an item is selected results in garbage being put into the edit window.

InsSortComboBox.zip (5 KB)
In this combo box, sorting is controlled by the AddString() function.
Style selected: vertical scroll
Styles not selected: owner-draw (fixed and variable), sort

Instructions

To incorporate CInsSortComboBox into a dialog box, put the following lines into the corresponding .H file:

#include "InsSortComboBox.h"   // near the top of the file
CInsSortComboBox m_comboChoices;   // among the attributes

In the corresponding .CPP file, put the following line among the include files:

#include "StringSANOrder.h"

Also put the following lines into OnInitDialog() before this control is referenced. Be sure to remove the corresponding variable from ClassWizard's list and to set the styles as above.

m_comboChoices.SubclassDlgItem (IDC_CHOICES_COMBO, this);
m_comboChoices.SetStringOrder (new CStringSANOrder());

The instructions for incorporating CSortListBox into an application are similar.



David Wincelberg
FileJockey Software
287 S. Robertson Blvd. PMB 373
Beverly Hills, CA 90211

File Jockey at Compu Serve dot com
(In the above line, change "at" and "dot" to their symbols and remove the spaces to produce my e-mail address.)

Return to main page
Last updated: 16-Nov-2008
Page address: http://www.FileJockeySoftware.com/ANO/index.html