Page 1 of 2

How to se focus and stay in second window?

Posted: Thu Sep 08, 2011 8:30 am
by mol
Hi guys!
I'm working on my billing project.
I want to create one window with new invoice and call second window with grid with table of goodies to sell.

I'm using something like that:
activate window F_Invoice, F_TableOfGoodies
to acitvate both windows.
F_TableOfGoodies is hidden from definition.

after pressing F6 key, I'm trying to move focus to F_TableOfGoodies:
F_TableOfGoodies.Show
F_TableOfGoodies.SetFocus


after these commands, form F_TableOfGoodies appear, but immediately losts focus.
So, my question is:
How to stop focus in F_TableOfGoodies to let the operator select position from table of goodies?

Did sb. realised such a problem?

Best regards, Marek

Re: How to se focus and stay in second window?

Posted: Thu Sep 08, 2011 8:40 am
by Rathinagiri
Marek,

Can you please post a small sample?

Re: How to se focus and stay in second window?

Posted: Thu Sep 08, 2011 8:48 am
by mol
It's hard to prepare sample because this project is very huge now.
I'll try to describe it:

1. Form Invoice appears on screen
2. Operator presses "Add Position" Button
3. Form Table_Of_Goodies appears on screen
4. Operator selects position from table and double clicks on it.
5. Form Table_Of_Goodies disappears from screen
6. Selected article is added to Invoice


Ive realised it by creating Table_of_Goodies everytime, when operator clicks "add" button.
But it takes too much time in network environment (I don't know why).
So, I want to hide this window, not release it.

Marek

Re: How to se focus and stay in second window?

Posted: Thu Sep 08, 2011 9:55 am
by Rathinagiri
Hi Marek,

Kindly see this small sample prepared by me. Is this what you need?

Code: Select all

#include <hmg.ch>

Function Main
   private cTarget := ''
   define window inv at 0, 0 width 600 height 400 main

      define label name1
         row 10
         col 10
         width 50
         value 'Item 1'
      end label
      define textbox item1
         row 10
         col 60
         width 100
         value ''
      end textbox
      define button b1
         row 10
         col 170
         width 80
         caption 'Add'
         action selectitem( 'item1' )
      end button
      define label name2
         row 40
         col 10
         width 50
         value 'Item 1'
      end label
      define textbox item2
         row 40
         col 60
         width 100
         value ''
      end textbox
      define button b2
         row 40
         col 170
         width 80
         caption 'Add'
         action selectitem( 'item2' )
      end button
   end window 

   define window items at 0, 0 width 200 height 300 child noshow 
      define listbox itemlist
         row 10
         col 10
         width 180
         height 240
         items { 'Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item  5', 'Item 6' }
         ondblclick itemselected()
         value 1
      end listbox
   end window
   inv.center
   items.center

   activate window inv, items
      
   Return

function selectitem( cTargetControl )
   cTarget := cTargetControl
   items.show
return nil

function itemselected
   setproperty( 'inv', cTarget, 'VALUE', items.itemlist.item( items.itemlist.value ) )
   items.hide
return nil

Re: How to se focus and stay in second window?

Posted: Thu Sep 08, 2011 11:44 am
by mol
Hi Rathi!

I've modified a little your sample to fit it to my situation, where INV form is called from MainWindow.
And then, something is going wrong:

Code: Select all

#include <hmg.ch>

Function Main
   private cTarget := ''
   define window MainWindow at 0, 0 width 600 height 400 main title "Testing program"

      define label name1
         row 10
         col 10
         width 200
         value 'Here is main window'
      end label
	  define button b1
         row 40
         col 170
         width 80
         caption 'Start test'
         action Start_test()
      end button
	end window
	
	MainWindow.center
	MainWindow.activate
 return

function Start_Test	

   define window inv at 0, 0 width 600 height 400 title "Invoice" modal
      define label name1
         row 10
         col 10
         width 50
         value 'Item 1'
      end label
      define textbox item1
         row 10
         col 60
         width 100
         value ''
      end textbox
      define button b1
         row 10
         col 170
         width 80
         caption 'Add'
         action selectitem( 'item1' )
      end button
      define label name2
         row 40
         col 10
         width 50
         value 'Item 1'
      end label
      define textbox item2
         row 40
         col 60
         width 100
         value ''
      end textbox
      define button b2
         row 40
         col 170
         width 80
         caption 'Add'
         action selectitem( 'item2' )
      end button
   end window

   define window items at 0, 0 width 200 height 300 title "Items" child noshow 
      define listbox itemlist
         row 10
         col 10
         width 180
         height 240
         items { 'Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item  5', 'Item 6' }
         ondblclick itemselected()
         value 1
      end listbox
   end window
   inv.center
   items.center

   activate window inv, items
     
   Return

function selectitem( cTargetControl )
   cTarget := cTargetControl
   items.show
return nil

function itemselected
   setproperty( 'inv', cTarget, 'VALUE', items.itemlist.item( items.itemlist.value ) )
   items.hide
return nil


Re: How to se focus and stay in second window?

Posted: Thu Sep 08, 2011 12:13 pm
by Rathinagiri
It is because of the 'modal' type of window definition.

So, either change 'inv' to 'child' or 'items' to 'modal' and try again.

Re: How to se focus and stay in second window?

Posted: Thu Sep 08, 2011 1:34 pm
by mol
I've tried with both modal windows and it doesn't work OK.
I can't use child window, because child window is not blocking main window.
I'll make some tests later.

Thanks, Rathi!

Re: How to se focus and stay in second window?

Posted: Thu Sep 08, 2011 1:49 pm
by Rathinagiri
For me, at least for this sample, it works by making both the windows as modal.

Re: How to se focus and stay in second window?

Posted: Sat Sep 10, 2011 10:37 am
by mol
Did you change anything in this code?

Re: How to se focus and stay in second window?

Posted: Sat Sep 10, 2011 11:30 am
by Rathinagiri
Yes. I have changed like the below:

Code: Select all

#include <hmg.ch>

Function Main
   private cTarget := ''
   define window MainWindow at 0, 0 width 600 height 400 main title "Testing program"

      define label name1
         row 10
         col 10
         width 200
         value 'Here is main window'
      end label
     define button b1
         row 40
         col 170
         width 80
         caption 'Start test'
         action Start_test()
      end button
   end window
   
   MainWindow.center
   MainWindow.activate
return

function Start_Test   

   define window inv at 0, 0 width 600 height 400 title "Invoice" modal
      define label name1
         row 10
         col 10
         width 50
         value 'Item 1'
      end label
      define textbox item1
         row 10
         col 60
         width 100
         value ''
      end textbox
      define button b1
         row 10
         col 170
         width 80
         caption 'Add'
         action selectitem( 'item1' )
      end button
      define label name2
         row 40
         col 10
         width 50
         value 'Item 1'
      end label
      define textbox item2
         row 40
         col 60
         width 100
         value ''
      end textbox
      define button b2
         row 40
         col 170
         width 80
         caption 'Add'
         action selectitem( 'item2' )
      end button
   end window

   define window items at 0, 0 width 200 height 300 title "Items" modal noshow
      define listbox itemlist
         row 10
         col 10
         width 180
         height 240
         items { 'Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item  5', 'Item 6' }
         ondblclick itemselected()
         value 1
      end listbox
   end window
   inv.center
   items.center

   activate window inv, items
     
   Return

function selectitem( cTargetControl )
   cTarget := cTargetControl
   items.show
return nil

function itemselected
   setproperty( 'inv', cTarget, 'VALUE', items.itemlist.item( items.itemlist.value ) )
   items.hide
return nil