Page 1 of 1
XBrowse: how to keep the selected row position
Posted: Sun Nov 22, 2020 8:10 am
by Enrico Maria Giordano
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
#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
Re: XBrowse: how to keep the selected row position
Posted: Sun Nov 22, 2020 3:26 pm
by cnavarro
Try with this
Code: Select all
#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
Re: XBrowse: how to keep the selected row position
Posted: Sun Nov 22, 2020 3:30 pm
by Enrico Maria Giordano
Thank you Cristobal, unfortunately your sample works exactly like mine. Did you try it? Am I missing something?
EMG
Re: XBrowse: how to keep the selected row position
Posted: Sun Nov 22, 2020 3:51 pm
by cnavarro
Try with this code, or use METHODS SaveState/RestoreState
Code: Select all
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
Re: XBrowse: how to keep the selected row position
Posted: Sun Nov 22, 2020 4:00 pm
by Enrico Maria Giordano
It seems to work, thank you.
EMG
Re: XBrowse: how to keep the selected row position
Posted: Sun Nov 22, 2020 4:06 pm
by Enrico Maria Giordano
Simplified code:
Code: Select all
#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