Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have a comboBox and in properties I put sort to false..but elements in comboBox are in alphabetical order, my code:

C++
for (INT_PTR nInd = 0; nInd < nNum; nInd++)
{
    combo_lin.AddString(theApp.m_arrL[nInd].m_strName);

    str = theApp.m_arrL[nInd].m_strName;


}



my data are:
italian
french
english


in comboBox I have:
english
french 
italian,


What I have tried:

I tried, as I told, to put sort to false
Posted
Updated 12-Apr-24 5:55am
v7
Comments
Richard Deeming 12-Apr-24 10:43am    
Telling the control not to sort isn't going to make any difference if the data you're adding is already sorted.

Beyond that, I doubt anyone will be able to help you based on the information provided.
Member 14594285 12-Apr-24 10:48am    
my data are:

italian
french
english

in comboBox I have:

english
french
italian,
I put my code
PIEBALDconsult 12-Apr-24 10:52am    
You should use the Improve question button to add that to the question.
Try putting the items in a different order and see what happens.
Richard MacCutchan 12-Apr-24 11:45am    
The code you have shown suggests that you are adding the same string each time, which makes no sense. Please show the actual data and the code you are using.
Member 14594285 12-Apr-24 11:52am    
I improve my question

The flag you are looking for is CBS_SORT. This sets the combobox up to automatically sort the strings. You can find bout more here[^].
 
Share this answer
 
Comments
Andre Oosthuizen 13-Apr-24 13:41pm    
To add to to this, you should also set the CBS_SORT style to be off for the combo box control. You can do this in your resource editor or programmatically using the 'CComboBox::ModifyStyle' method.
You need to use the 'CComboBox::InsertString' method instead of 'CComboBox::AddString' method, see - MS Learn | CComboBox Class[^]

Your code should be -

C++
for (INT_PTR nInd = 0; nInd < nNum; nInd++) {
    int index = combo_lin.InsertString(nInd, theApp.m_arrL[nInd].m_strName);
    if (index == CB_ERR) {
        // Handle error
    }
    str = theApp.m_arrL[nInd].m_strName;
}
 
Share this answer
 
Comments
Member 14594285 15-Apr-24 2:53am    
thank you very much!! it's very simple

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900