Click to See Complete Forum and Search --> : CComboBox, SetCurSel... VC++ 5.0...bug??


Harvey Hawes
April 22nd, 1999, 12:16 AM
Hi,

Here's the problem. I populate a combobox in a dlg with 16 strings. The combobox is not set to sort.

The strings added in position 2 and 9 are the same. In the dlgbox OnInitDlg handler (after I fill the combo), I call m_ctrlCombo.SetCurSel(9). This function returns "9". If I call m_ctrlCombo.GetCount() I get 16. Why, then, when the dlg is displayed, is the 2nd item selected?

Is there a bug?

I'm using VC++ 5.0 (no SP's)

Thanks for any help,

Harvey Hawes

Software Engineer
BioScience Analysis Software Ltd.

Masters Candidate
Cardiovascular/Respiratory Sciences
Faculty of Medicine
University of Calgary
Calgary, Alberta, Canada

April 22nd, 1999, 01:19 AM
Hello,

Look on you help the fonction GetCount dont return the curant selected string index but the total number of string !

Chainard Arnaud :
At : Terrasse.Gaetan@wanadoo.fr

eric33
April 22nd, 1999, 01:56 AM
For me your code seems correct.
The only thing i see is that you may have a string member variable linked to your listbox (using DDX). If after selected the item you used UpdateData(TRUE) and then UpdateData(FALSE) I think the second item will be selected (because of the same string value).

If this do not solve your problem try to put a code sample in the faq.

April 22nd, 1999, 02:10 AM
Hi:
this is a problem that i had meet.
In fact the strings has been added,but not displayed
when you put a combo box into the form,you click it,
and you can drag its bottom to make it larger,and the
problem is solved.
sorry for my poor english.

your friend:
yaohaihong
e-mail address:yaohaihong@990.net

sally
April 22nd, 1999, 02:47 AM
If the strings can have the same value, why have them there IDENTIFIED by their test. Use the DWORD in the ComboBox instead...

sally

Sally
April 22nd, 1999, 02:47 AM
If the strings can have the same value, why have them there IDENTIFIED by their test. Use the DWORD in the ComboBox instead...

sally

Harvey Hawes
April 22nd, 1999, 11:52 AM
Hi,

You got it right on. I stepped through the code, and had m_ctrlCombo.GetCurSel() in the watch window. It changes right after a call to UpdateData(FALSE) (which was called after UpdateData(TRUE)).

I've never really understood what that function does. Maybe you could clear things up for me.

Thanks,



Harvey Hawes

Software Engineer
BioScience Analysis Software Ltd.

Masters Candidate
Cardiovascular/Respiratory Sciences
Faculty of Medicine
University of Calgary
Calgary, Alberta, Canada

April 24th, 1999, 10:33 AM
UpdateData(TRUE) retrieves the value from the fields to the members variables of your class bound to the fields using DDX.

UpdateData(FALSE) makes the reverse. It means it puts the value from the member variables to the windows control.

I hope this could help.