Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,

i have a combobox created via the visual designer (not dynamically) and i wanna modify its drop-down liste limit via code. I have to do in that way because in my code i moved the combobox to some place so the dropdown parameter has changed (to zero).

i found some code as below wich make the modification limit possible


C#
void SetDropDownHeight(CComboBox* pMyComboBox, int itemsToShow)
{
    //Get rectangles
    CRect rctComboBox, rctDropDown;
    //Combo rect
    pMyComboBox->GetClientRect(&rctComboBox);
    //DropDownList rect
    pMyComboBox->GetDroppedControlRect(&rctDropDown);

    //Get Item height
    int itemHeight = pMyComboBox->GetItemHeight(-1);
    //Converts coordinates
    pMyComboBox->GetParent()->ScreenToClient(&rctDropDown);
    //Set height
    rctDropDown.bottom = rctDropDown.top + rctComboBox.Height() + itemHeight*itemsToShow;
    //apply changes
    pMyComboBox->MoveWindow(&rctDropDown);
}


the prob : the application crashes when i try to execute this line

C++
SetDropDownHeight(&m_CodeAgence, 5);


thank you
Posted
Comments
Zasky 13-Mar-12 10:29am    
How is m_CodeAgence declared?
Nelek 13-Mar-12 14:13pm    
And which message do you get when your application steps into the error?

If you have the chance then step with your debugger into the functions and you will see exactly at which point your program crashes.

From just statically looking at your code, my best guess would be that pMyComboBox is an invalid pointer and that you get an access violation.

Second chance is that pMyComboBox points to a CComboBox object, but the m_hWnd in it is not yet initialized, i.e. your dialog initialization has not been completed yet.

Hope that helps you pin-point the problem.
 
Share this answer
 
Comments
Schehaider_Aymen 14-Mar-12 7:06am    
Hi, the m_CodeAgence variable is a CComboBox and my application crashes on

pMyComboBox->GetClientRect(&rctComboBox);

and yes it looks that i'm in the second case (the m_hwnd is not yet initialized) i call thit fucntion in the OnInitialUpdate().
After I retrieve a CComboBox from the CWnd related to the ComboBox and worked.

thank you for your answers.
 
Share this answer
 

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