Combo Box edit/delete

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

edk
Posts: 304
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 81 times
Been thanked: 233 times

Re: Combo Box edit/delete

Post by edk » Fri Feb 16, 2018 10:22 am

Here is sample:

Code: Select all

// http://www.hmgforum.com/viewtopic.php?f=9&t=127
/*
   HMG Dynamic ComboBox Demo

   (c) 2008 Bicahi Esgici

*/

#include "minigui.ch"

#define CMBMAXITCOUNT 10

Function Main

    PRIV aSrcStrgs := { "","A","B","C","D","E" }
    PRIV Form1_Combo1_Val := 0

    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 GOTFOCUS IF(form_1.combo_1.value > 0, (ADD_ALTdel(), Form1_Combo1_Val:=form_1.combo_1.value ), Nil );
            ON LOSTFOCUS (REM_ALTdel(), DynCmbDone() ) ;
            ON ENTER  DynCmbDone() ;
            ON CHANGE Form1_Combo1_Val:=form_1.combo_1.value;
            DROPPEDWIDTH 250
          
            Form1_Combo1_Val:=form_1.combo_1.value

         
        @ 10,230 TEXTBOX txbDummy         // For forcing combo to lostfocus

    END WINDOW

    CENTER WINDOW Form_1

    ACTIVATE WINDOW Form_1

RETURN // Main()

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

PROCEDURE ADD_ALTdel()
ON KEY ALT+DELETE OF Form_1 ACTION IF(MsgYesNo('Confirm delete?','Delete',.T.), ;
  					(Form1_Combo1_Val:=form_1.combo_1.value, Form_1.Combo_1.DeleteItem( Form1_Combo1_Val), Form_1.Combo_1.Value := MIN( Form_1.Combo_1.ItemCount, Form1_Combo1_Val ) ) ,;
    					Nil)
RETURN

PROCEDURE REM_ALTdel()
ON KEY ALT+DELETE OF Form_1 ACTION Nil
RETURN


PROC DynCmbDone()
   IF Form1_Combo1_Val == 1 .AND. !EMPTY( Form_1.Combo_1.DisplayValue )		//add
   	 aSrcStrgs := ARRAY( Form_1.Combo_1.ItemCount )
   	 AEVAL( aSrcStrgs, { |x, y| aSrcStrgs [y] := Form_1.Combo_1.Item( y ) } )
   	 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
      
   IF Form1_Combo1_Val > 1 .AND. !EMPTY( Form_1.Combo_1.DisplayValue )	//change
     Form_1.Combo_1.Item( Form1_Combo1_Val ) := Form_1.Combo_1.DisplayValue
     Form_1.Combo_1.Value := Form1_Combo1_Val
   ENDIF

RETU // DynCmbDone()

*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._
Adding new items by typing the content in the first (empty) item.
Editing item, if it's not the first (empty) item.
You can delete a selected item by Alt + Delete.

RPC
Posts: 127
Joined: Fri Feb 10, 2017 4:12 am
DBs Used: DBF
Has thanked: 30 times
Been thanked: 7 times

Post by RPC » Fri Feb 16, 2018 2:01 pm

Excellent edk.
This is what I wanted.
You have helped me again. Sometime back you helped me with file downloads from internet.
Many many thanks :D

User avatar
esgici
Posts: 4439
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 324 times
Been thanked: 99 times
Contact:

Post by esgici » Fri Feb 16, 2018 3:23 pm

edk wrote:
Fri Feb 16, 2018 10:22 am
Here is sample:
...
Thanks Edward,

good improvement 8-)

Viva HMG :D
Viva INTERNATIONAL HMG :D

Post Reply