In order for this site to work correctly we need to store a small file (called a cookie) on your computer. Most every site in the world does this, however since the 25th of May 2011, by law we have to get your permission first. Please abandon the forum if you disagree.

Para que este foro funcione correctamente es necesario guardar un pequeño fichero (llamado cookie) en su ordenador. La mayoría de los sitios de Internet lo hacen, no obstante desde el 25 de Marzo de 2011 y por ley, necesitamos de su permiso con antelación. Abandone este foro si no está conforme.

ComboBox:cText problem

Xailer professional forum in English
Responder
Avatar de Usuario
Hurricane
Mensajes: 262
Registrado: Mar Mar 24, 2015 10:21 am
Ubicación: Brasil
Contactar:

ComboBox:cText problem

Mensaje 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
Adjuntos
cbxText.zip
(2.6 KiB) Descargado 73 veces
Avatar de Usuario
ignacio
Site Admin
Mensajes: 9253
Registrado: Lun Abr 06, 2015 8:00 pm
Ubicación: Madrid, Spain
Contactar:

Re: ComboBox:cText problem

Mensaje 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,
Ignacio Ortiz de Zúñiga
[Equipo de Xailer / Xailer team]
https://www.xailer.com
Avatar de Usuario
Hurricane
Mensajes: 262
Registrado: Mar Mar 24, 2015 10:21 am
Ubicación: Brasil
Contactar:

Re: ComboBox:cText problem

Mensaje 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
Avatar de Usuario
ignacio
Site Admin
Mensajes: 9253
Registrado: Lun Abr 06, 2015 8:00 pm
Ubicación: Madrid, Spain
Contactar:

Re: ComboBox:cText problem

Mensaje 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,
Ignacio Ortiz de Zúñiga
[Equipo de Xailer / Xailer team]
https://www.xailer.com
Responder