Page 1 of 1
Collapse drop down in combobox from the program? (SOLVED)
Posted: Thu Oct 24, 2019 7:06 pm
by ic2
I use a subclassed Combobox which auto drops down using the following code:
METHOD FocusChange( oEvent ) CLASS Ic2ComboBox
IF lGotFocus // Drop down automatically each time control receives focus
PostMessage( SELF:Handle(), CB_SHOWDROPDOWN, 1, 0L )
ENDIF
Problem is when I assign a value to the combobox manually it also drops down where it shouldn't. I thought to counteract that as follows:
SELF:oDCMyComboBox:VALUE:="Some value present in the elements of the combobox"
SendMessage(SELF:oDCMyComboBox:Handle(), CB_SHOWDROPDOWN,0, 0)
but it does not collapse and stays dropped down.
How can I achieve that?
Dick
Collapse drop down in combobox from the program?
Posted: Thu Oct 24, 2019 11:54 pm
by TimothyS
Hi Dick,
What about:
EXPORT lDrop := TRUE as LOGIC
METHOD FocusChange( oEvent ) CLASS Ic2ComboBox
IF lGotFocus .and. SELF:lDrop // Drop down automatically each time control receives focus
PostMessage( SELF:Handle(), CB_SHOWDROPDOWN, 1, 0L )
ENDIF
SELF:lDrop := TRUE
METHOD Set_Value( uNewValue as usual)
self:value := uNewValue
self:lDrop := FALSE
RETURN NIL
Then assign as per below:
SELF:oDCMyComboBox:Set_Value( "Some value present in the elements of the combobox")
Haven't tested this, but might help.
Regards,
Tim
Collapse drop down in combobox from the program?
Posted: Fri Oct 25, 2019 7:52 am
by FFF
Timothy Shea wrote:
Code: Select all
METHOD Set_Value( uNewValue as usual)
self:value := uNewValue
self:lDrop := FALSE
RETURN NIL
Might be better to swap:
self:lDrop := FALSE
self:value := uNewValue
Collapse drop down in combobox from the program?
Posted: Fri Oct 25, 2019 10:14 am
by ic2
Hello Thomoty, Karl,
Thanks for the reply. This is one of those situations where it's hard to understand what the computer is doing. I tried something like this already and refined it with your remarks. What happened?
// Set the lDropDown variable here
SELF:oDCMyComboBox:VALUE:="Some value"
- Despite the above settings, _Debout shows lDropDown is false in FocusChange!
- The FocusChange does NOT seem to be called directly after assigning a value. I put a few statements with waiting time in it to see what happens
- Then some totally unrelated code is executed
- AFTER THAT the FocusChange is executed, with lDropDown false, so still dropping down the combobox.
Solved
I did solve it however:
PostMessage( SELF:oDCMyComboBox:Handle(), CB_SHOWDROPDOWN, 0, 0L )
Contrary to SendMessage this statement actively lets the combobox collapse. It now drops down and directly collapses at the right time, where the statement is exectuted.
Dick