Page 1 of 1

Set Focus in DCBrowseCol

Posted: Sun Jan 05, 2014 7:19 pm
by GeneB
I am trying to set the focus in a browse to a specific cell.
In the example below, the data in a cell is tested and if the test fails
the cell is cleared and I want the focus to remain in the cell
instead of moving to the next one.
Thanks.

Code: Select all

   DCBROWSECOL ELEMENT 1 HEADER 'Item' WIDTH 15  ;
               PARENT oInput         ;
               PROTECT {|| .F. }     ;
               EDITOR 'ItemEditor'

      @ nil,nil DCGET xNil PICTURE REPL("!",20)     ;
        GETID 'ItemEditor'                          ;
        VALID {|oGet,cItem,o|                  ;
                 cItem := oGet:Get:VarGet()   ;
               , cItem := IF(OkItem(cItem), cItem, SPACE(20) ) ;
               , oGet:Get:VarPut(cItem)        ;
               , oGet:Get:UpdateBuffer()       ;
               , oInput:refreshCurrent()       ;
               , IF(EMPTY(cItem), ???? set focus back to this cell ????, nil ) ;
               , .T. } 

Re: Set Focus in DCBrowseCol

Posted: Mon Jan 06, 2014 9:04 am
by rdonnay
Your VALID statement should return a .FALSE.. You have it returning a NIL.

Re: Set Focus in DCBrowseCol

Posted: Mon Jan 06, 2014 9:55 am
by Tom
IMHO, it returns always .T.

Re: Set Focus in DCBrowseCol

Posted: Mon Jan 06, 2014 10:09 am
by rdonnay
IMHO, it returns always .T.
Tom - You are always right. :clap:

Re: Set Focus in DCBrowseCol

Posted: Mon Jan 06, 2014 9:25 pm
by GeneB
Thanks. This of course keeps the cursor in the cell, but the cell then turns blue and the cursor is at the same position within the cell not left aligned.
I'm not well versed in Xbase (went from Clipper straight to Express, that was the allure), so I was wondering what the Xbase code would be within the Valid block so that a touch typist can resume typing in the cell, cell not blue, cursor aligned left, without reaching for a mouse.
Thank you.

Re: Set Focus in DCBrowseCol

Posted: Tue Jan 07, 2014 1:30 am
by skiman
Hi,

Change this

Code: Select all

... , IF(EMPTY(cItem), ???? set focus back to this cell ????, nil ) ;
    , .T. } 
to

Code: Select all

...  , IF(EMPTY(cItem), .f., .t. ) ;
     } 

Re: Set Focus in DCBrowseCol

Posted: Tue Jan 07, 2014 5:51 am
by GeneB
thanks. I still would like to know the way to give 'uncolored' focus to the original cell and reset the cursor all the way to the left.

Re: Set Focus in DCBrowseCol

Posted: Tue Jan 07, 2014 6:49 am
by reganc
Could you not use oGet:home() in your valid statement to move the cursor to the leftmost position?

Re: Set Focus in DCBrowseCol

Posted: Tue Jan 07, 2014 9:28 am
by skiman
Hi,

I expected that when your 'cItem' is empty, the valid returns .F. and the cursor stays in the cell. Isn't that the case? It should!

Re: Set Focus in DCBrowseCol

Posted: Tue Jan 07, 2014 9:29 pm
by GeneB
Thank you both for your help.
Adding oGet:home() was the solution.

I now use the following:

Code: Select all

        VALID {|oGet,cItem,o|                  ;
                 cItem := oGet:Get:VarGet()    ;
               , cItem := IF(OkItem(cItem), cItem, SPACE(20) ) ;
               , oGet:Get:VarPut(cItem)        ;
               , oGet:Get:UpdateBuffer()       ;
               , oGet:home()                   ;
               , oInput:refreshCurrent()       ;
               , IF(EMPTY(cItem), .F., .T.) }
Without "home()" the cursor remains at the last position used in the cell instead of the first position.

This routine is useful when user input has to be located and verified as already in a dbf file.
When the entry isn't appropriate, clearing the cell allows the user to type it again without reaching for a mouse. The cell turns blue for the second try, which I assume is only the default color, but the cursor is in the left position and visible so I can live with that. It actually highlights the cell for another try at input so it might be better.

Thanks to everyone for their help.