XBrowse: how to keep the selected row position

XBrowse: how to keep the selected row position

Postby Enrico Maria Giordano » Sun Nov 22, 2020 8:10 am

In this sample, try to press the down arrow and then ESC. The new dialog doesn't keep the position of the selected row but moves it to the top.

Is there a way to keep the selected row position?

Code: Select all  Expand view
#include "Fivewin.ch"


FUNCTION MAIN()

    USE CUSTOMER

    TEST()

    TEST()

    RETURN NIL


STATIC FUNCTION TEST()

    LOCAL oDlg, oBrw

    DEFINE DIALOG oDlg;
           SIZE 800, 600

    @ 0, 0 XBROWSE oBrw

    oBrw:CreateFromCode()

    ACTIVATE DIALOG oDlg;
             ON INIT oDlg:SetControl( oBrw );
             CENTER

    RETURN NIL


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8711
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: XBrowse: how to keep the selected row position

Postby cnavarro » Sun Nov 22, 2020 3:26 pm

Try with this
Code: Select all  Expand view

#include "Fivewin.ch"

Static nRowPos := 1

FUNCTION MAIN()

    USE CUSTOMER

    TEST()

    TEST()

    RETURN NIL


STATIC FUNCTION TEST()

    LOCAL oDlg, oBrw

    DEFINE DIALOG oDlg;
           SIZE 800, 600

    @ 0, 0 XBROWSE oBrw

    oBrw:CreateFromCode()
    oBrw:Keyno( nRowPos )

    ACTIVATE DIALOG oDlg;
             ON INIT oDlg:SetControl( oBrw );
             CENTER
    nRowPos  := oBrw:KeyNo

    RETURN NIL

 
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: XBrowse: how to keep the selected row position

Postby Enrico Maria Giordano » Sun Nov 22, 2020 3:30 pm

Thank you Cristobal, unfortunately your sample works exactly like mine. Did you try it? Am I missing something?

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8711
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: XBrowse: how to keep the selected row position

Postby cnavarro » Sun Nov 22, 2020 3:51 pm

Try with this code, or use METHODS SaveState/RestoreState
Code: Select all  Expand view


Static nRowPos := 1
Static nRowSel := 1

FUNCTION MAIN()

    USE CUSTOMER

    TEST()

    TEST()

    RETURN NIL


STATIC FUNCTION TEST()

    LOCAL oDlg, oBrw

    DEFINE DIALOG oDlg;
           SIZE 800, 600

    @ 0, 0 XBROWSE oBrw

    oBrw:CreateFromCode()
    oBrw:Keyno( nRowPos )
    oBrw:nRowSel := nRowSel
    oBrw:Refresh()


    ACTIVATE DIALOG oDlg;
             ON INIT oDlg:SetControl( oBrw );
             CENTER
    nRowPos  := oBrw:KeyNo
    nRowSel  := oBrw:nRowSel

    RETURN NIL

 
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España


Re: XBrowse: how to keep the selected row position

Postby Enrico Maria Giordano » Sun Nov 22, 2020 4:06 pm

Simplified code:

Code: Select all  Expand view
#include "Fivewin.ch"


FUNCTION MAIN()

    USE CUSTOMER

    TEST()

    TEST()

    RETURN NIL


STATIC FUNCTION TEST()

    LOCAL oDlg, oBrw

    STATIC nRowSel := 1

    DEFINE DIALOG oDlg;
           SIZE 800, 600

    @ 0, 0 XBROWSE oBrw

    oBrw:CreateFromCode()

    oBrw:nRowSel = nRowSel

    ACTIVATE DIALOG oDlg;
             ON INIT oDlg:SetControl( oBrw );
             CENTER

    nRowSel = oBrw:nRowSel

    RETURN NIL


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8711
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Enrico Maria Giordano and 96 guests