Pre-Selected Itembox
Keywords: pre-select itembox by default
Question:
On one of my dialogs I wanted to have an itembox control with multiple pre-selected items (actually I wanted all items to be pre-selected). I found that I could do that by specifying my variable %var% in the pre-selected item box. I can also have multiple adjacent items selected by either using another variable with the items in it or by: "item1%@TAB%item2"Is there any way to pre-select multiple non-adjacent items? Maybe I could sort my list so that the items I wanted were already adjacent.
Answer:
If you have a lot of items, and you want them all selected....and there are a lot of them... then you need a dialog callback where you set them all in the initialization step.Using a dialog callback procedure and a DialogControlSet request code 6 set in the initialization section of the dialog proc. You can set them all that way.
Question:
On one of my dialogs I wanted to have an itembox control with single pre-selected items. I am using the Dialog Callback Procedures Initialization routine to Pre-select the item. I also am using the function IntControl 33, to tell the Itembox to only allow a single item to be selected. The problem is the item is not being pre-selected in the dialog. Why?Here is my code:
#DEFINESUBROUTINE PreSetExample(Handle,DialogMessage,DialogControlID,param4,param5) switch (DialogMessage) case 0 IntControl(33,0,0,0,0) DialogControlSet(Handle,003,6,"Grapes") break; endswitch return -1 #ENDSUBROUTINE list = StrCat("Apples",@tab,"Oranges",@tab,"Grapes") MyDialogFormat=`WWWDLGED,6.1` MyDialogCaption=`WIL Dialog 1` MyDialogX=002 MyDialogY=050 MyDialogWidth=208 MyDialogHeight=153 MyDialogNumControls=003 MyDialogProcedure=`PreSetExample` MyDialogFont=`DEFAULT` MyDialogTextColor=`DEFAULT` MyDialogBackground=`DEFAULT,DEFAULT` MyDialog001=`30,129,034,011,PUSHBUTTON,DEFAULT,"OK",1,1,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog002=`123,130,033,011,PUSHBUTTON,DEFAULT,"Cancel",0,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog003=`001,001,202,116,ITEMBOX,list,DEFAULT,DEFAULT,3,DEFAULT,DEFAULT,DEFAULT,DEFAULT` ButtonPushed=Dialog("MyDialog") ExitAnswer:
IntControl 33 must be used outside the Callback Procedure. The problem your seeing is a result of using IntControl 33 with in the callback instead of outside the call back routine. What is happening is that you are calling IntControl 33 after the Itembox really already *exists*. The Intcontrol may be re-initializing the ItemBox, hence why you are not seeing the pre-selected item.Moving the IntControl 33, to just before you define the dialog.
#DEFINESUBROUTINE PreSetExample(Handle,DialogMessage,DialogControlID,param4,param5) switch (DialogMessage) case 0 DialogControlSet(Handle,003,6,"Grapes") break; endswitch return -1 #ENDSUBROUTINE IntControl(33,0,0,0,0) ;Notice this IntControl must be used outside the Callback Procedure. list = StrCat("Apples",@tab,"Oranges",@tab,"Grapes") MyDialogFormat=`WWWDLGED,6.1` MyDialogCaption=`WIL Dialog 1` MyDialogX=002 MyDialogY=050 MyDialogWidth=208 MyDialogHeight=153 MyDialogNumControls=003 MyDialogProcedure=`PreSetExample` MyDialogFont=`DEFAULT` MyDialogTextColor=`DEFAULT` MyDialogBackground=`DEFAULT,DEFAULT` MyDialog001=`30,129,034,011,PUSHBUTTON,DEFAULT,"OK",1,1,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog002=`123,130,033,011,PUSHBUTTON,DEFAULT,"Cancel",0,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog003=`001,001,202,116,ITEMBOX,list,DEFAULT,DEFAULT,3,DEFAULT,DEFAULT,DEFAULT,DEFAULT` ButtonPushed=Dialog("MyDialog") Exit
Article ID: W15129