Ahsan Amin


I have a form that contains navigation button. I want to enable or disable the button according to the position of cursor/record pointer e.g i want don't to enable move previous and go first record button if the pointer is on first record.



Re: Record Pointer Position

dni


You may put in click method of button something like:

IF RECNO() = 1

thisform.Yourbutton.Enabled = .F.

GO TOP

ELSE

thisform.Yourbutton.Enabled = .T.

ENDIF







Re: Record Pointer Position

Naomi Nosonovsky

Here is what I have in toolbar's Refresh method (in your case you can put all buttons in the container)

LPARAMETERS tcCondition
LOCAL llBOF, ;
llEOF

IF PCOUNT() = 0
tcCondition = ""
ENDIF

llBOF = BOF() OR (tcCondition = "BOF")
llEOF = EOF() OR (tcCondition = "EOF")

*-- Update navigation buttons
this.cmdFirst.Enabled = !llBOF
this.cmdPrior.Enabled = !llBOF
this.cmdNext.Enabled = !llEOF
this.cmdLast.Enabled = !llEOF

RETURN

This is not my code, but it works. It assumes that the main navigation alias is currently the selected alias.






Re: Record Pointer Position

Ahsan Amin

i am already doing like this. The code is written on form Init event. When i run the form the pointer is on first record and according to code the button move first and next shoudl be disabled but they are not.





Re: Record Pointer Position

MarciaAkins

Ahsan Amin wrote:

I have a form that contains navigation button. I want to enable or disable the button according to the position of cursor/record pointer e.g i want don't to enable move previous and go first record button if the pointer is on first record.

Add a method called SetButtons to the form and call it whenever you have clicked on one of the navigation buttons and when you instantiate the form. You pass this method the current position in the table and it refreshes all of the buttons:

Code Snippet

Lparameters tuNewPos

Local lcNewPos

lcNewPos = ""

*** Check parameter. Although designed to be called with a string,

*** we will allow for a numeric value to be used as well.

If Vartype( tuNewPos ) = "C"

lcNewPos = Upper( Alltrim( tuNewPos ))

Else

If Vartype( tuNewPos ) = "N" And Between( tuNewPos, 1, 3 )

lcNewPos = Iif( tuNewPos = 1, 'FIRST', lcNewPos )

lcNewPos = Iif( tuNewPos = 2, 'MID', lcNewPos )

lcNewPos = Iif( tuNewPos = 3, 'LAST', lcNewPos )

Else

*** Anything else is invalid, so just exit

Return .F.

Endif

Endif

*** Now handle the buttons, first enable them all

With This

.SetAll( 'Enabled', .T. )

Do Case

Case lcNewPos = 'MID'

*** Handle the most common situation first - which is

*** now 'do nothing' since all buttons are enabled anyway

Case lcNewPos = 'FIRST'

*** Turn Off, First and Previous

.CmdFirst.Enabled = .F.

.CmdPrior.Enabled = .F.

Case lcNewPos = 'LAST'

.CmdLast.Enabled = .F.

.CmdNext.Enabled = .F.

Otherwise

*** There is no otherwise, other than an error!

Return .F.

Endcase

Endwith

*** Add the Return for debugging

Return .T.