Page 1 of 1

Dynamic ComboBox

Posted: Tue Oct 07, 2008 4:58 pm
by esgici
Hi all

I have tried a "Dynamic" ComboBox. Dynamic means changeable at runtime.

The code is here :

Code: Select all

/*
   HMG Dynamic ComboBox Demo

   (c) 2008 Bicahi Esgici
   
*/

#include "minigui.ch"
        
#define CMBMAXITCOUNT 10
  
Function Main

    PRIV aSrcStrgs := { '' }
    
    DEFINE WINDOW Form_1 ;
        AT 0,0 ;
        WIDTH 400 ;
        HEIGHT 200 ;
        TITLE 'Dynamic ComboBox Demo' ;
        MAIN

      ON KEY ESCAPE ACTION Form_1.Release

        @ 10,10 COMBOBOX Combo_1 ;
            WIDTH  200  ;
            HEIGHT 200 ;
            ITEMS aSrcStrgs ;
            VALUE 1 ;
            DISPLAYEDIT ;
            ON LOSTFOCUS DynCmbDone() ;
            ON ENTER  DynCmbDone() ;
            DROPPEDWIDTH 250
            
        @ 10,230 TEXTBOX txbDummy         // For forcing combo to lostfocus
            
    END WINDOW

    CENTER WINDOW Form_1

    ACTIVATE WINDOW Form_1

RETURN // Main()

*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._


PROC DynCmbDone()

   IF Form_1.Combo_1.Value == 0 .AND. !EMPTY( Form_1.Combo_1.DisplayValue )       
      IF LEN( aSrcStrgs ) <= CMBMAXITCOUNT
         AADD( aSrcStrgs,  )
      ENDIF    
      AINS( aSrcStrgs, 1 )
      aSrcStrgs[ 1 ] := ''
      aSrcStrgs[ 2 ] := Form_1.Combo_1.DisplayValue
      Form_1.Combo_1.DeleteAllItems()
      AEVAL( aSrcStrgs, { | c1 | Form_1.Combo_1.AddItem( c1 ) } )
      Form_1.Combo_1.Value := 2
   ENDIF   

RETU // DynCmbDone()

*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._
I am not sure that this is the best way and I hope that may be many betters.

Any opinion ?

Regards

--

esgici

Re: Dynamic ComboBox

Posted: Sat Feb 05, 2011 7:52 pm
by Rathinagiri
I am sorry that I had not seen this thread. :(

Thanks a lot Esgici for giving the link.

I like your idea a lot.

Re: Dynamic ComboBox

Posted: Sat Feb 05, 2011 8:35 pm
by esgici
Hi Rathi
rathinagiri wrote:I am sorry that I had not seen this thread. :(
Please don't worry my friend; really there isn't any problem by my side.
rathinagiri wrote:I like your idea a lot.
The important is that, thank you very much. :D

Regards

--

Esgici