Combo Box sorting
-
I'm working on MS Visual C++ 6.0. I have a dialog with a combo box on it. Since it needs to display the items in sorted order, i have checked the 'sort' feature available by right-clicking on the combo box and choosing "Sort". This does the job, except that the sorting takes place such that 11 appears before 2 (because the sorting is string based). I need the sorting done based on the length too i.e it should appear as 9, 10 ,11 and not 10, 11 and then 9. How can I edit the "Sort" functionality of the combo box? :^)
-
I'm working on MS Visual C++ 6.0. I have a dialog with a combo box on it. Since it needs to display the items in sorted order, i have checked the 'sort' feature available by right-clicking on the combo box and choosing "Sort". This does the job, except that the sorting takes place such that 11 appears before 2 (because the sorting is string based). I need the sorting done based on the length too i.e it should appear as 9, 10 ,11 and not 10, 11 and then 9. How can I edit the "Sort" functionality of the combo box? :^)
what are the values that your combo carry. are they fixed? or are they going to change regularly.
-------------------------------------------- Suggestion to the members: Please prefix your main thread subject with [SOLVED] if it is solved. thanks. chandu.
-
I'm working on MS Visual C++ 6.0. I have a dialog with a combo box on it. Since it needs to display the items in sorted order, i have checked the 'sort' feature available by right-clicking on the combo box and choosing "Sort". This does the job, except that the sorting takes place such that 11 appears before 2 (because the sorting is string based). I need the sorting done based on the length too i.e it should appear as 9, 10 ,11 and not 10, 11 and then 9. How can I edit the "Sort" functionality of the combo box? :^)
AFAIK you should
- disable the automatic (lexicographic) sort of the combobox.
- Sort yourself the items on insertion.
:)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
I'm working on MS Visual C++ 6.0. I have a dialog with a combo box on it. Since it needs to display the items in sorted order, i have checked the 'sort' feature available by right-clicking on the combo box and choosing "Sort". This does the job, except that the sorting takes place such that 11 appears before 2 (because the sorting is string based). I need the sorting done based on the length too i.e it should appear as 9, 10 ,11 and not 10, 11 and then 9. How can I edit the "Sort" functionality of the combo box? :^)
This is a common problem with listbox types that sort on string values and do not take account of numbers. I think the only way to get your items in the correct order is to sort them manually and then add them to an unsorted combobox.
It's time for a new signature.
-
I'm working on MS Visual C++ 6.0. I have a dialog with a combo box on it. Since it needs to display the items in sorted order, i have checked the 'sort' feature available by right-clicking on the combo box and choosing "Sort". This does the job, except that the sorting takes place such that 11 appears before 2 (because the sorting is string based). I need the sorting done based on the length too i.e it should appear as 9, 10 ,11 and not 10, 11 and then 9. How can I edit the "Sort" functionality of the combo box? :^)
For a fixed owner draw combo box, handle WM_COMPAREITEM of parent dialog. Or create your own CComboBox derived class and over-ride CComboBox::CompareItem(). Implement your comparison logic there :) CComboBox::CompareItem WM_COMPAREITEM Message
-
what are the values that your combo carry. are they fixed? or are they going to change regularly.
-------------------------------------------- Suggestion to the members: Please prefix your main thread subject with [SOLVED] if it is solved. thanks. chandu.
-
in that case, follow what experts said below. i.e. you have to sort them manually.
liz3 wrote:
they are not fixed. Will change regularly.
it would be good, if you can narrate your task, with an example. like, 1.are they going to have only numeric values? or can it have text too. 2.will it be loaded at the initiation of the application? or in between while operation on the UI. 3.please narrate what are the different possible values and what are the conditions, at which the values get addd to the combo. all the best.
-------------------------------------------- Suggestion to the members: Please prefix your main thread subject with [SOLVED] if it is solved. thanks. chandu.
-
I'm working on MS Visual C++ 6.0. I have a dialog with a combo box on it. Since it needs to display the items in sorted order, i have checked the 'sort' feature available by right-clicking on the combo box and choosing "Sort". This does the job, except that the sorting takes place such that 11 appears before 2 (because the sorting is string based). I need the sorting done based on the length too i.e it should appear as 9, 10 ,11 and not 10, 11 and then 9. How can I edit the "Sort" functionality of the combo box? :^)
In addition to the above suggestions, I offer the following. If you don't mind the items of the combo box items look a bit different, and also you know the maximum width of the numbers, you can pad the items with leading zeros. This way, with the "sort" property set to true, the items will sort correctly. For example, if you know the maximum width will be two, then format the items like this: 02, 09, 11, 10, etc. Hope this helps.