Página 1 de 1

ComboBox:cText problem

Publicado: Lun Ene 03, 2022 11:45 pm
por Hurricane
Hi,

After selecting an item, TComboBox:cText does not have the correct value.
This will happen if you use csDROPDOWN.

I have attached a project with the example.

troubleshooter: (Are there any different alternatives?)

Código: Seleccionar todo

METHOD CbxCloseUp( oSender ) CLASS TForm1
   ::LOADFILES(.t.)
   RETURN Nil

//------------------------------------------------------------------------------
METHOD LOADFILES( lIndex ) CLASS TForm1
   if lIndex .and. ::oCbx:nIndex > 0
      ::oCbx:cText:=::oCbx:aItems[::oCbx:nIndex]
   endif
   ::oLabel1:cText:=::oCbx:cText

   RETURN NIL

METHOD CbxKeyDown( oSender, nKey, nFlags ) CLASS TForm1
   if nKey = VK_RETURN
      ::LOADFILES(.f.)
      return 0
   endif
   RETURN Nil

Re: ComboBox:cText problem

Publicado: Mar Ene 04, 2022 2:01 pm
por ignacio
Hi,

As you can see in the source code, we only trap Windows messages and trigger our own events.

Código: Seleccionar todo

METHOD Command( nNotifyCode ) CLASS XComboBox

   DO CASE
      ......
      CASE nNotifyCode == CBN_CLOSEUP
         ::OnCloseUp()
	RETURN 0
      ......
   ENDCASE

RETURN ::Super:Command( nNotifyCode )
And do not ask me why, Microsoft decided to send the message CBN_CLOSEUP before changing its underlying value. I suggest you use the OnChange event instead of OnCloseUp.

Regards,

Re: ComboBox:cText problem

Publicado: Mar Ene 04, 2022 6:44 pm
por Hurricane
Hi,
I think the Xailer needs some additional code to fix. On Lazarus it worked. In Xailer it works only with the csDROPDOWNLIST style.
With the OnChange event it doesn't work either. After selection cText is out of date.
And the proper event depends on the logic applied to the form, I'm using 3 combobox events.
ignacio escribió: Mar Ene 04, 2022 2:01 pm And do not ask me why, Microsoft decided to send the message CBN_CLOSEUP before changing its underlying value. I suggest you use the OnChange event instead of OnCloseUp

Re: ComboBox:cText problem

Publicado: Mar Ene 04, 2022 6:59 pm
por ignacio
Modify TCombobox wit this code:

Código: Seleccionar todo

METHOD WMXailer( w, l, h ) INLINE IIF( w == CBN_CLOSEUP, ::OnCloseUp(), )

METHOD Command( nNotifyCode ) CLASS XComboBox

   DO CASE
      CASE nNotifyCode == CBN_DBLCLK
         ::OnDblClick()
	RETURN 0
      CASE nNotifyCode == CBN_DROPDOWN
         IF ::nDroppedWidth == -1 //Calculado
            ::SetDroppedWidth()
         ENDIF
         ::OnDropDown()
	RETURN 0
      CASE nNotifyCode == CBN_CLOSEUP
         ::PostMsg( WM_XAILER, CBN_CLOSEUP, 0 )  <<<<<<<<<<<<<<<<<<<< NEW CODE
         //::OnCloseUp()
	 RETURN 0
BTW, I'm not sure if we should put this code in production, so I suggest you overload this class for your own purposes.

Regards,