GET@h

Hi,
I have an MFC dialog application which opens another dialog box containing some combo boxes.
I wanted some elements from the comboboxes to be selected by default so I used the member function SetCurSel but it did not work! It generates a Debug Assertion Failed in afxwin2.inl line 769!
I went through some posted questions in the forum but that did not help. I tried to move the code I used to select the default item to the OnCreate/OnShow/OnInitDialog member function of the dialog but still does not work.
Is there anything wrong with this

Thanks,



Re: Visual C++ General CComboBox Assertion failed

Red Swingline Stapler

If you haven't already done so, make sure that the call to SetCurSel() takes place after you create your combo boxes.

Also, OnInitDialog() is the standard place to perform these kinds of initializations. Make sure your call to SetCurSel occurs after the base class has been called.

If you've already done this, please post some sample code- in particular your OnInitDialog function, and let us know whether you are creating the combo boxes programmatically or via a resource.





Re: Visual C++ General CComboBox Assertion failed

GET@h

Hi,

Thanks for the answer.

I created my ComboBoxes using the Visual Studio Wizard, the comboboxes are than created on the stack and not on the heap. So, I thought there is no need to call the create method.

Did I do something wrong here

Thanks & regards,






Re: Visual C++ General CComboBox Assertion failed

Pintu Shukla

Can you SHow your Code here .How you used SetCurSel Method in your code. i am sure this problem arise due to invalid Window Handle .just check out your codes once again. have a look on the few step mention down

1 ) Create a Combobox on your Dialog.

4) Create member variable of your ComBoBox with the help of Class Wizard and don't forget to mention Variable type to control or if you don't want to use Class Wizard . Simply create a Object of ComboBox class in your code Implement DDX method manually in your code (DDX_Control()) .

4) Now try Once again with this newly Created ComboBox Object.

Hope this will work proper for you.

Thanx






Re: Visual C++ General CComboBox Assertion failed

GET@h

Hi,Thanks for the answer. Yes, the assertion is due to an invalid window handle.
I used my comboboxes exactly as what you described.
The combobox is created by the Class Wizard and here is what it generated:

in myFile.h
Code Block

CComboBox SampleIntervalComboBox;


in myFile.cpp
Code Block

void MyDialog::DoDataExchange(CDataExchange* pDX){
CDialog::DoDataExchange(pDX);
DDX_Control (pDX, IDC_SAMPLEINTERVAL_COMBO, SampleIntervalComboBox);
DDX_CBIndex (pDX, IDC_SAMPLEINTERVAL_COMBO, sampleIntervalSelectedIndex);
}

BOOL MyDialog::OnInitDialog(){
SampleIntervalComboBox.SetCurSel(1); // Select the first item in the combobox.
return TRUE;
}



Please not that my combobox has by default severla items that I set using the properties of the combobox.
The assertion happens when I try to display my dialog so I assume the invalid window handle is detected in the OnInitDialog member function.

Regards,





Re: Visual C++ General CComboBox Assertion failed

Viorel.

I think calling of inherited OnInitDialog function must not be by-passed and it should be done before other operations. Therefore I would suggest adding a line to your OnInitDialog:

Code Block

BOOL MyDialog::OnInitDialog()

{

__super::OnInitDialog(); // (or CDialog::OnInitDialog())

. . .

}

Otherwise DoDataExchange is probably not called. I hope this helps.





Re: Visual C++ General CComboBox Assertion failed

GET@h

Hi,
Yes, you are completly right!
That solved the problem
Thanks a lot.