WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Dialog Editor
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Itembox use with variable

Keywords:	 Itembox select Item box in dialog Editor use with variable param

Question:

I have a dialog with one or more Itemboxes. The user may select one or more items from the lists. In the same main window, I also have a 'Help' button. This button will display an AskFileText with some information related to the main window. But when the user clicks on OK in the AskFileText window, the ItemBox(es) in the main window will no longer display all its original items, only the items that were selected before Help button was clicked on!

Any ideas? Do I need to refeed the ItemBoxes when they get redrawn?

Also, can I make it so the user can select only one item in the ItemBox? (I may have already asked this long time before)

Answer:

Yes you will need to reinitialize the ItemBoxes. When the user hits the button, you exit the dialog, and then restart it later. It will use the value of the listbox variables, which is the items the user selected.

Here is a demonstration of the issue and its resolution using the functions DialogControlGet and DialogControlSet.


GoSub ReadAllFunctions
GoSub ReadAllSubs

Message("ItemBox Save Selected Demo",IntroMessage)

varDemoAmPm = StrCat("AM",@TAB,"PM")

While 1
   resp = AskYesNo("Display Dialog?","Show the dialog (again)?")
   If Resp Then GoSub IBDemoDialog
   Else Break
EndWhile

Exit ;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

:ReadAllFunctions ;===========================================================================
#DefineFunction IBDemoCallbackProc(IBDemo_Handle,IBDemo_Message,IBDemo_Name,IBDemo_EventInfo,rsvd)
    InitDialogConstants()                                   ; Initialize Dialog Constants
    varIbAmPmFullList = StrCat("AM",@TAB,"PM")              ; Used to repopulate the ItemBox
    GoSub ShowHideAllControls
   ON_EQUAL = @TRUE                                         ; Initialize variable ON_EQUAL
   Switch IBDemo_Message                                    ; Switch based on Dialog Message type
      Case MSG_INIT                                         ; Standard Initialization message
;         DialogProcOptions(IBDemo_Handle,MSG_TIMER,1000)
         DialogProcOptions(IBDemo_Handle,MSG_BUTTONPUSHED,@TRUE)
;         DialogProcOptions(IBDemo_Handle,MSG_EDITBOX,@TRUE)
;         DialogProcOptions(IBDemo_Handle,MSG_ITEMSELECT,@TRUE)
         Return(RET_DO_DEFAULT)

     Case MSG_BUTTONPUSHED
        If IBDemo_Name == "pbAl_OK"                        ; &OK
            GoSub ShowHideAllControls
        Return(RET_DO_DEFAULT)

        EndIf                                              ; IBDemo_Name
        Return(RET_DO_DEFAULT)

   EndSwitch                                                ; IBDemo_Message
      :ShowHideAllControls ;---------------------------------------------------------------------
;---------------------------------------------------------------------------------------------
;--- UnComment next two lines to disable saving user response in ItemBox ----------------------
      Return ;Disables the ShowHideAllControls sub when active
      :Dummy
;--- UnComment above two lines to disable saving user response in ItemBox ----------------------
;---------------------------------------------------------------------------------------------
         sel = DialogControlGet(IBDemo_Handle, "ibDemoAmPm", DC_ITEMBOXCONTENTS)
         If ItemCount(Sel,@TAB) < 2 Then
            DialogControlSet(IBDemo_Handle, "ibDemoAmPm", DC_ITEMBOXCONTENTS, varIbAmPmFullList)
            DialogControlSet(IBDemo_Handle, "ibDemoAmPm", DC_ITEMBOXSELECT, sel)
         EndIf
      Return ;ShowHideAllControls Local Sub -----------------------------------------------------
   Return(RET_DO_DEFAULT)
#EndFunction                                                ; End of Dialog Callback IBDemoCallbackProc
Return ;ReadAllFunctions

:ReadAllSubs ;================================================================================
IntroMessage = ""
IntroMessage = StrCat(IntroMessage,"Demo: saving item selected in ItemBox control.",@CRLF,@CRLF)
IntroMessage = StrCat(IntroMessage,"You must run the dialog twice to view the PROBLEM, then",@CRLF)
IntroMessage = StrCat(IntroMessage,"edit the script where shown on lines 43 and 44, then",@CRLF)
IntroMessage = StrCat(IntroMessage,"run the script twice more. Cancel button will exit.")

#DefineSubRoutine InitDialogConstants()
   ;DialogprocOptions Constants (ABBREVIATED LIST!)
   MSG_INIT=0                ; The one-time initialization
   MSG_TIMER=1               ; Timer event
   MSG_BUTTONPUSHED=2        ; Pushbutton or Picturebutton
   MSG_EDITBOX=5             ; Editbox or Multilinebox
   MSG_ITEMSELECT=7          ; Itembox
   MSG_MENUITEM=15           ; MenuItem selected

   ;DialogControlState Constants
   DCSTYLE_DEFAULT=0         ; Set Default Style

   ;DialogControlSet / DialogControlGet Constants
   DC_ITEMBOXCONTENTS=5      ; ITEMBOX FILELISTBOX DROPLISTBOX
   DC_ITEMBOXSELECT=6        ; ITEMBOX FILELISTBOX DROPLISTBOX

   ;DialogObject constants

   ;Return code constants
   RET_DO_CANCEL=0           ; Cancels dialog
   RET_DO_DEFAULT= -1        ; Continue with default processing for control
   RET_DO_NOT_EXIT= -2       ; Do not exit the dialog
   Return
#EndSubRoutine ;==============================================================================
Return ;ReadAllSubs ==========================================================================

:IBDemoDialog ;-------------------------------------------------------------------------------
IBDemoFormat=`WWWDLGED,6.2`

IBDemoCaption=`ItemBox Save Selected Demo`
IBDemoX=300
IBDemoY=132
IBDemoWidth=148
IBDemoHeight=109
IBDemoNumControls=007
IBDemoProcedure=`IBDemoCallbackProc`
IBDemoFont=`DEFAULT`
IBDemoTextColor=`DEFAULT`
IBDemoBackground=`DEFAULT,128|128|128`
IBDemoConfig=0

IBDemo001=`079,017,036,024,ITEMBOX,"ibDemoAmPm",varDemoAmPm,"AM",DEFAULT,50,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
IBDemo002=`017,017,014,012,EDITBOX,"ebDemoTiHr",varDemoTimeHour,DEFAULT,DEFAULT,30,DEFAULT,"Microsoft Sans Serif|7680|40|34","0|0|0",DEFAULT`
IBDemo003=`049,017,014,012,EDITBOX,"ebDemoTiMi",varDemoTimeMin,DEFAULT,DEFAULT,40,DEFAULT,"Microsoft Sans Serif|7680|40|34","0|0|0",DEFAULT`
IBDemo004=`049,087,042,012,PUSHBUTTON,"pbAl_OK",DEFAULT,"&OK",1,180,32,DEFAULT,DEFAULT,DEFAULT`
IBDemo005=`019,007,018,008,STATICTEXT,"stDemoSetHr",DEFAULT,"Hour:",DEFAULT,300,DEFAULT,"Microsoft Sans Serif|6144|40|34","0|0|0",DEFAULT`
IBDemo006=`051,007,016,010,STATICTEXT,"stDemoSetMi",DEFAULT,"Min:",DEFAULT,300,DEFAULT,"Microsoft Sans Serif|6144|40|34","0|0|0",DEFAULT`
IBDemo007=`005,040,134,038,STATICTEXT,"stBlurb",DEFAULT,"Select  AM / PM and watch the other item disappear after clicking OK and re-displaying the dialog. Then, edit the script where shown to fix, then do again.",DEFAULT,70,DEFAULT,"Microsoft Sans Serif|7680|40|34","128|0|0",DEFAULT`

ButtonPushed=Dialog("IBDemo")

Return ;IBDemoDialog -------------------------------------------------------------------------

Article ID:   W12846
Filename:   Itembox Use with Variable.txt
File Created: 2010:07:06:09:12:52
Last Updated: 2010:07:06:09:12:52