setting focus on a listbox item

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

setting focus on a listbox item

Post by kpassaur » Wed Mar 07, 2007 11:10 pm

I have a script below that has two lists. One list is static and the user can add or remove items to the second list from the items in the first. They can also change the order of the items. However, when changing order and the Dialog is refreshed, the item selected in the past is not selected. What is selected is the item that is now in its place. In other words, if the third item was selected in the past and it is now the second item (because the user hit the move up key) the third item is still selected. Ideally the second item in the list would be selected.

If the second item was selected the user could just contine to press the up button and watch the item move up with out having to click on it to select is again.

So what I need to do is figure out how to setfocus on the new item.

Code: Select all



Let>Staticlist=C:\temp\docTypes.txt
Let>Variablelist=C:\temp\CDfilelist.txt

Gosub>Sub1
Gosub>Sub2

SRT>Sub1
Let>list1=
Let>Staticlisttxt=
Let>k=1
Label>start1
ReadLn>%Staticlist%,k,list1
If>list1=##EOF##,finish1
ConCat>%list1%,%CRLF%
Let>Staticlisttxt=%Staticlisttxt%%list1%
Let>k=k+1
Goto>start1
Label>finish1
END>Sub1


SRT>Sub2
Let>z=1
Let>Variablelisttxt=
Label>start2
ReadLn>%Variablelist%,z,list2
If>list2=##EOF##,finish2
ConCat>%list2%,%CRLF%
Let>Variablelisttxt=%Variablelisttxt%%list2%
Let>z=z+1
Goto>start2
Label>finish2
END>Sub2


Dialog>Dialog1
   Caption=Dialog1
   Width=468
   Height=460
   Top=151
   Left=538
   ListBox=msListBox1,64,80,121,185,%Staticlisttxt%
   ListBox=msListBox2,248,80,121,185,%Variablelisttxt%
   Button=Exit,192,344,75,25,2
   Button=>,200,96,41,25,1
   Button=<200>Dialog1



Show>Dialog1
Label>Dialog1loop
GetDialogAction>Dialog1,result
If>result=2,Donewithit
If>result=1,Addtolist
If>result=3,removefromlist
If>result=4,moveonup
If>result=5,moveondown
If>result=10,EOF
Goto>Dialog1loop

SRT>Addtolist
WriteLn>%Variablelist%,result,%Dialog1.msListBox1%
GoSub>Sub2
//MDL>%Variablelisttxt%
Let>Dialog1.msListBox1.Items.Text=Staticlisttxt
Let>Dialog1.msListBox2.Items.Text=Variablelisttxt
ResetDialogAction>Dialog1
END>Addtolist

SRT>removefromlist
DeleteFile>c:\temp\templist.txt
CopyFile>%Variablelist%,c:\temp\templist.txt
DeleteFile>%Variablelist%

Let>w=1
Label>wstart
ReadLn>c:\temp\templist.txt,w,wline
If>wline=##EOF##,wfinish
If>wline=%Dialog1.msListBox2%,skipthislinew
WriteLn>%Variablelist%,result,%wline%
Label>skipthislinew
Let>w=w+1
Goto>wstart
Label>wfinish
GoSub>Sub2
Let>Dialog1.msListBox1.Items.Text=Staticlisttxt
Let>Dialog1.msListBox2.Items.Text=Variablelisttxt
ResetDialogAction>Dialog1
END>removefromlist


SRT>Donewithit
CloseDialog>Dialog1
Let>result=10
END>Donewithit





///////////////////////////////////////////========================Beginning of Up Sub
SRT>moveonup
GoSub>getorder

If>x=1,nochange
Sub>x,1
DeleteFile>c:\temp\templist.txt
CopyFile>%Variablelist%,c:\temp\templist.txt
DeleteFile>%Variablelist%
Let>u=1
Label>ustart
Let>moved=NO
ReadLn>c:\temp\templist.txt,u,uline
If>uline=##EOF##,ufinish
If>u=x,changeordersub
If>%moved%=YES,skipthislineu
WriteLn>%Variablelist%,result,%uline%
Label>skipthislineu
Let>u=u+1
Goto>ustart
Label>ufinish
GoSub>Sub2
Let>Dialog1.msListBox1.Items.Text=Staticlisttxt
Let>Dialog1.msListBox2.Items.Text=Variablelisttxt
ResetDialogAction>Dialog1
      SRT>changeordersub
      ADD>u,1
      ReadLn>c:\temp\templist.txt,u,uline
      WriteLn>%Variablelist%,result,%uline%
      Sub>u,1
      ReadLn>c:\temp\templist.txt,u,uline
      WriteLn>%Variablelist%,result,%uline%
      Let>moved=YES
      ADD>u,1
      END>changeordersub
Label>nochange
End>moveonup
///////////////////////////////////////////========================End of Up Sub
SRT>moveondown
GoSub>getorder
ADD>x,1
If>x=o,nochangedown
Sub>x,1
//MDL>%x% %o%
//Goto>EOF

DeleteFile>c:\temp\templist.txt
CopyFile>%Variablelist%,c:\temp\templist.txt
DeleteFile>%Variablelist%
Let>d=1
Label>dstart
Let>moved=NO
ReadLn>c:\temp\templist.txt,d,dline
If>dline=##EOF##,dfinish
If>d=x,changeordersubd
If>%moved%=YES,skipthislined
WriteLn>%Variablelist%,result,%dline%
Label>skipthislined
Let>d=d+1
Goto>dstart
Label>dfinish

GoSub>Sub2
Let>Dialog1.msListBox1.Items.Text=Staticlisttxt
Let>Dialog1.msListBox2.Items.Text=Variablelisttxt
ResetDialogAction>Dialog1
    
	
	  SRT>changeordersubd
      Add>d,1
      ReadLn>c:\temp\templist.txt,d,dline
      WriteLn>%Variablelist%,result,%dline%
      Sub>d,1
      ReadLn>c:\temp\templist.txt,d,dline
      WriteLn>%Variablelist%,result,%dline%
      Let>moved=YES
      ADD>d,1
      END>changeordersubd
Label>nochangedown
End>moveondown



SRT>getorder
Let>selected=%Dialog1.msListBox2%
Gosub>Sub2
Separate>%Variablelisttxt%,%CRLF%,Orderoflist
If>Orderoflist_count=0,endoforder
Let>o=0
Repeat>o
               Let>o=o+1
			   If>Orderoflist_%o%=%Selected%
			   Let>x=o
               Endif
Until>o,Orderoflist_count
Label>endoforder
END>getorder

Label>EOF


I'm sure it can be done just don't know how and it would make a nice touch.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts