Sorting Items in a Combo Box...

I have a Combo Box that is sub-classed. I want the items in the list to be 
sorted by the lParam of the item and then alphabetically (upper and lower 
case separately).

The dialog control being sub-classed has the Sort property set to true, but 
it isn't sorting them, or if it is, it is doing so in reverse of what I want. 
For example, the list contains "r, D, .s, .., and ." which is the order is 
displays them in from top to bottom, but I want the reverse ("., .., .s, D, 
r").

I tried setting up the CompareItem(), but it doesn't seem to be called.

FWIW:
- The ComboBox is a Drop Down (CBS_DROPDOWN) style.
- The data is being entered internally by the class via InsertString(), and 
then the lParam data is set via SetItemData().

Am I doing something wrong?

TIA,

BRM
0
BRM1 (16)
8/18/2004 8:57:02 PM
vc.mfc 33608 articles. 0 followers. Follow

1 Replies
737 Views

Similar Articles

[PageSpeed] 24

CompareItem() is only called if your combo box is owner-drawn.

If you don't want to go this route, then how about having a sorted data store
that backs the combo box?  

There is a very nice sorted array class on CodeProject, CSortedArray, that I
have used and which works fabulously, and it has a nice callback Compare()
function that you can code to sort any way you like.  It has a member function
called OrderedInsert, which returns the index at which the item was inserted,
which is just what you need.

In fact, here is the article that contains CSortedArray from CodeProject.  The
author is doing something similar to what you want to do, although he is usting
a tree control:

http://www.codeproject.com/treectrl/filetree.asp

Backing up a bit, are strings added to the box dynamically, i.e., by user
interaction?  If not, simply sort the strings the way you want and then add them
to the combo box in your sorted order.

If strings are added on the fly by the user, and you want them sorted, you could
add the string to a sorted array, which backs the combo box items, get the index
of the newly added string in the array, and use InsertItem to insert it in the
combo box at this index.

Whenever you add an item to the box, add it to the array first, get the index,
then add it to the box with this index.  Whenever you delete an item from the
box, also delete it from the array, i.e., you must keep the array and the box in
synch.

I can't think of any way to control the sorting using just the combo box, unless
you want the default sorting, which you don't, or unless you set the box to
owner draw.

On Wed, 18 Aug 2004 13:57:02 -0700, BRM <BRM@discussions.microsoft.com> wrote:

>I have a Combo Box that is sub-classed. I want the items in the list to be 
>sorted by the lParam of the item and then alphabetically (upper and lower 
>case separately).
>
>The dialog control being sub-classed has the Sort property set to true, but 
>it isn't sorting them, or if it is, it is doing so in reverse of what I want. 
>For example, the list contains "r, D, .s, .., and ." which is the order is 
>displays them in from top to bottom, but I want the reverse ("., .., .s, D, 
>r").
>
>I tried setting up the CompareItem(), but it doesn't seem to be called.
>
>FWIW:
>- The ComboBox is a Drop Down (CBS_DROPDOWN) style.
>- The data is being entered internally by the class via InsertString(), and 
>then the lParam data is set via SetItemData().
>
>Am I doing something wrong?
>
>TIA,
>
>BRM

0
none89 (807)
8/19/2004 4:48:19 AM
Reply:

Similar Artilces:

change treeview item, without activity in tree
Hi Using the following code I defined that when Im loading the Announcements into the program it marks the some of them with various icons in the TreeView. This was fairly easy, because when I pasted a new element into the tree (hTemp = GetTreeCtrl().InsertItem(pDoc- >m_pAnnouncements[ann].m_cAnnouncementName, SecondParentItem, TVI_LAST);), I got the tree element back into the hTemp variable, and I could easily change the picture. My question would be that how could I go through the Announcements and modify their icons, but without clicking anywhere in the tree. Thanks for any help in for...

Sorting
Hi, is it possible to use variable for sorting? Something like: declare @sort varchar(10) SET @sort='column1 DESC' SELECT ROW_NUMBER() OVER (ORDER BY @sort)AS rowId, * FROM table Is dynamic SQL only option? Thank you, Simon On 15/04/2010 11:28, simon wrote: > Hi, > > is it possible to use variable for sorting? > > Something like: > > declare @sort varchar(10) > SET @sort='column1 DESC' > > SELECT ROW_NUMBER() OVER (ORDER BY @sort)AS rowId, * FROM table > > Is dynamic SQL only option? You can use CASE to he...

How to sort account list?
I'm using MS Money 2004 Small Business. In the account list, my accounts are catagorized by and in this order: - bank accounts - credit accounts - investment accounts - loans and liabilities - asset accounts TOTAL BALANCE In the above view, I cannot easily determine totals for assets and liabilities. The following view does this. - bank accounts - investment accounts - asset accounts SUBTOTAL -loans and liabilities SUBTOTAL TOTAL BALANCE How do I get the above view? Thanks, Brett I don't use Small Business. But you can run a Net Worth report to get total assets and ...

Importing additional contact info (appending), attaching items to contacts
Hello, I have a few general-purpose outlook questions for the folks on this group. First of all, I would like to know if there is a way to access outlook data in a "flat" form. I would like to append notes to about 3000 contacts that I currently have in a Public Contacts Folder, and I am not sure how I can actually append the notes to the contact records, instead of re-creating the contact records. Any clues? Second, we have had some trouble with the "activities view" on contacts. Could anyone here explain how it might be configured for best use? What I am thinking ri...

Where's the Sort by New Message option?
Not sure when the layout of the newsgroups changed but I can't seem to find the ability to sort by new message in a thread instead of sorting by just the original thread date. That was hugely helpful as I could follow along and see what threads were still active. If you're gonna hang around in the newsgroups (any newsgroups), you may want to start using a newsreader. Microsoft Outlook Express can do it for you. Saved from a previous post: You may want to connect to the ms newsserver directly: If you have Outlook Express installed, try clicking on these links (or copy and paste i...

Row names will not move with sort
Each row in my summary table in Sheet1 is hyperlinked to a corresponding table in Sheet2 with additional details. I need to move the rows in my summary table (Sheet1) and preserve the links to and from the details tables (Sheet2). I found that I can move rows in Sheet1 with cut & insert and the hyperlinks are maintained. I can travel from a row in summary table (Sheet1) to details table (Sheet2) and back, even after the corresponding row (Sheet1) was moved. But if I sort the rows in Sheet1 the links from Sheet2 back to corresponding rows in Sheet1 lead to presorted locations. Apparen...

sorts not sorting
OK- Thanks to everyones help I now i have a list i can work with... but there are a few problems.... the zips are all 5 digit and now i have to sort them... the problem is, THEY WONT SORT CORRECTLY!!!!!!! The numbers are not in order... some are but a lot are not... is there anyway to fix this???? i need to sort them by zip code but cant seem to get them to do it correctly.. any ideas??? ------------------------------------------------ ~~ Message posted from http://www.ExcelTip.com/ ~~ View and post usenet messages directly from http://www.ExcelForum.com/ You are going to be far better of...

Can I print a barcode for an Assembly item?
As in the actual Itemlookup code for the Assembly and not the items in the assembly. Ivan "Ivan Brebner" <ibrebner@premiumretail.com.au> wrote in message news:u98TAFd7FHA.2600@tk2msftngp13.phx.gbl... > > ...

Time problem in sent items
Windows XP, Outlook XP, in my sent all ( work with IMAP Folders ) my time appears to be +10 hours than my actual local time, my local settings on my computer are correct Can anyone help me ? Thanks CJ .. Outlook will follow Windows lead, so if the time is incorrect in Windows, don't bother opening outlook. Check your time zone and BIOS time. ~jason "CJ Foster" <anonymous@discussions.microsoft.com> wrote in message news:041901c3cf41$bade98c0$a501280a@phx.gbl... > Windows XP, Outlook XP, in my sent all ( work with IMAP > Folders ) my time appears to be +10 hour...

import- number- sort?
I imported this data into a spread sheet- I tried to format it to number, but when I sort it- I get : 37.08 4.33 4.79 4.8 42.56 5.94 Whats up with this? Thanks Brent Hi Brent, Install the TrimAll macro, select the column and invoke the macro from Alt+F8 http://www.mvps.org/dmcritchie/excel/join.htm#trimall Directions to install and use a macro at http://www.mvps.org/dmcritchie/excel/getstarted.htm#havemacro I expect that you have spaces or CHAR(128) "Required Blank" characters in you data you can check is =LEN(A1) --- HTH, David...

Multiple Line Invoice Non-Inventory Item Descriptions
What is the recommended way to accomodate more than 3 lines of description for a non-inventory invoice line item? I've had people do it different ways. One way has been using the item comment field. Another way has been to use Extender to provide a longer description field. "Scott Rutledge" <Scott Rutledge@discussions.microsoft.com> wrote in message news:1CE42F6C-3633-4A1F-8C27-40D3BFAAF80C@microsoft.com... > What is the recommended way to accomodate more than 3 lines of description > for a non-inventory invoice line item? The lines would need to be differen...

2003 Crash and Drop Down Boxes
I have two problems... I have a software package for wineries that I have had for about 11 years. The first program I never had any problems. As the program and the user base grew, I needed to add a Point Of Sale interface, which is much more complicated than the original invoice. Along the way the application began crashing. It was always during a change that cause the intire form to recalculate. I minimized the problem by not haveing some of the fields recalcualte except on demand - meaning I added a button which did the form calculations on request and not when the form(s) were ...

sorting macro #3
I need to sort on 8 cells in a row and on 1500+rows. I can do it one at a time but I know there must be an easier way. Can ANYONE HELP? C3:J3 I need these cells sorted and then down to C1532:J1532 I did create a macro to sort after I selected them but still one at a time. Does it have to be a macro? I can edit a macro but don't really know how to program them. Yes, it has to be a macro. The following should do it. This macro loops through all the entries in Column C, and in each row it sorts the values in Columns C:J. HTH Otto Sub SortRows() Dim rColC As Range Dim i As...

Can we sort a form and also be able to enter new records.
Hi, It is possible to sort the data on a form and also be able to enter new and edit the existing records in it. Cheers! On Tue, 15 Jan 2008 15:41:16 -0800 (PST), Rex wrote: > Hi, > > It is possible to sort the data on a form and also be able to enter > new and edit the existing records in it. > > Cheers! I assume you mean "Is it". The form sort order has nothing to do with editing or adding new records, so the answer is yes. If you cannot edit or add new records, make sure the form's record source, if it is a query, is updateable. Some queries are not. O...

Sorting checking register
How do i sort my check register in Money 2004 Deluxe so that uncleared transactions appear below cleared transactions? In Quicken i could click on the column to provide that sort. In microsoft.public.money, Dean wrote: >How do i sort my check register in Money 2004 Deluxe so >that uncleared transactions appear below cleared >transactions? In Quicken i could click on the column to >provide that sort. You don't. Available choices are chosen by clicking View at the top of the register. ...

Manager can update membership list check box
Hi, I'm working with W2K3 and E2K3. Is there a way to setup 'Active Directory Users and Computers' on a workstation so that the check box for 'Manager can update membership list check box' (Distribution Group, Managed by tab) appears? So far I can only make that work by remoting into an Exchange server, but that won't work for administrators, we need them to do this from their desktops. Thanks, Mindy Mindy: ADUC is probably overkill for just managing distribution group memberships. Can the manager just manage them through Outlook by selecting the properti...

using addrress books to sort incoming mail
I use address books to sort incoming mail. An odd thing: depending on how the sender's name comes across, it doesn't get caught by the filter (amd moved to the "Family Mail" Folder I have set up. for example: my mom and dad's email (from momanddad@somedomain.com) comes as from that address. However, in my contacts, they are listed by their names: John and Mary Smith, with momanddad@somedomain.com as their email address and John and Mary Smith as the display name. What have I done wrong? TIA 1. The big ONE - failed to post your version of Outlook. Rules operate at ...

Outlook 2003 Can't Open Item MS OFFICE FAILED
Yikes, I'm having a real problem. I am running Windows XP with Service Pack 2 Home Edition Office 2003 with Service Pack 2 (only have Outlook and Word installed) Toshiba Notebook M15-S405 Satellite Pro 1.4 ghz with 512 mgs ram I woke up one morning and saw that I had a stop error window open on my computer explaining that Windows had encountered some kind of driver error and that windows had to restart. Windows offered that I review my system for serious errors. That is a very sad thing to wake up to. So I ran a chkdsk and defragged and a virus check. No problems there. I checked my ...

"Can't open this item" error
Hello, I have an email that's been sitting in my Inbox for about three months. I can't delete it, reply to it, move it, forward it, anything. I always get an error "Can't open this item", "Unknow Error" etc. Is there a way to get rid of the email. I heard that Working Offline might work, but I don't know how to do that. Can you please help? Thanks, Joe Turn off the preview pane and see if you can now delete it. --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. After searching google.groups.com and fin...

Outlook 2002 Deleted Items Folder
Recently, emails that I place in the "Deleted Items" folder are auotmatically deleted. That is, you can not look at the emails that you put into this folder, or change your mind. They are gone. How do I turn off this function? I like to review this folder,in case I accidently put in an important email. Ed, Expand your folders to make sure that you don't have two deleted folders (i.e. try that other than the Deleted Items in the toolbar to the right.) See if they are in another folder and you just think its deleting them. If it keeps doing it, you could create a rule...

Unmerge so I can sort
I coy/pasted data into Excell and when I try to sort it I get "This operation requires merged sells to be identically sized". I understadn the work around in KB but how do I find which sells are merged? I wouldn't bother looking. I'd just remove all the merged cells from the range to sort. Select that range format|cells|alignment tab uncheck the merge cells box But if you wanted to search, you can do it via process of elimination. Select a range, format|cells|alignment tab. If that merge cells box is checked, then the whole selection is merged. If it's grey, t...

Automatic Dropdown of Combo Box
I have read the posts and tried the previous suggestions and it is not working. I have a combo box that I want to automatically drop down when the field is selected like when you tab into or Enter Key from a previous field. I have tried Me.comboboxname.Dropdown in both "On Enter" and "Got FOcus" with no change. Suggestions?? Private Sub comboboxname_GotFocus() Me.comboboxname.Dropdown End Sub should certainly work, regardless of how you access the combobox; OnEnter won't work, I don't think, if you click on the box. How did you enter the code? By...

sorting issue
Hi, When a range of columns are highlighted and a sort is performed on only one column empty cells above the sort display first. How can this be prevented. I know when there is data in any of the other column but not on the column being sorted this will happen. Any thoughts? Pat Are you sure the cells are really empty? They don't contain spaces or even formulas that evaluate to "". (Even formulas converted to values that returned "")? Pat wrote: > > Hi, > > When a range of columns are highlighted and a sort is performed on only one > column em...

Recurring Calendar items question
Outlook 2003. Hmmm. The Calendar extension in Thunderbird/Firefox, allows this. If you have a recurring appointment or event, say weekly over a period of weeks but there is one week in the middle of the period where the event or appointment is NOT happening, then Thunderbird/Firefox calendar allows you to put that date in the recurring event/appointment as an exception so you don't get reminded about a non-existent happening! I can't see a similar function in Outlook 2003 calendar...... There may be another way, but I'm aware that when you have a recurring series of events...

Populate Combo Box with Access Table Data
Hello, I have an acccess table that contains WellName, Date, Hours and Rate as well as some other columns of information. I am trying to set up a combo box in Excel that will allow me to select a WellName from the Access table, and then populate 3 separate columns in the spreadsheet with the data from Date, Hours and Rate. Example: WellName Date Hours Gas_Rate 100010205922W500 18/11/2009 0 0 100010205922W500 19/11/2009 2.48 2980 100010205922W500 20/11/2009 1.43 990 100010205922W500 24/11/2009 13.94 240 100010205922W500 22/11/2009 13.71 24...