Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » CExtComboBox auto sort Collapse All
Subject Author Date
Darren Oliver Nov 6, 2006 - 1:03 PM

Hi Support.

I’ve searched the forums for this simple question but I have not found any discussion about it.

I have a CExtComboBox where I’m inserting strings in a particular order. However by default this order is sorted alphabetically so GetCurSel no longer returns the index based on the order I inserted the strings.

ie. I insert "B", then "A". I expect "B" to be at index 0 since it’s the first string I inserted. However when "B" is selected from the list GetCurSel returns 1.

1. Is there a way to disable the alphabetical sorting of items in the list box?

or even better

2. Is there a way to get the index based on the order I entered strings into the list even if the list was rearranged to be sorted?

Thanks!

Suhai Gyorgy Nov 7, 2006 - 2:40 AM

This is a purely MFC question.

1. You can remove the CBS_SORT style of your combobox with ModifyStyle, or in Visual Studio in design mode look for the Sort property in the property list of the combobox and set it to false.

2. With sorting switched on, you can achieve what you want with a code similar to this one:

for (int i = 0; i < NO_OF_DATA; i++) {
	int iAddedIndex = m_comboBox.AddString(m_strings[i]);
	m_comboBox.SetItemData(iAddedIndex, i);
}
 ... 
// later on you want to find out the index of the entering:
int iEnteredIndex = m_comboBox.GetItemData(iVisibleIndex);