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.
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.
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
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.
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:
Lparameters
tuNewPosLocal
lcNewPoslcNewPos
= ""*** 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. EndifEndif
*** Now handle the buttons, first enable them all
With This
.SetAll( 'Enabled', .T. ) Do CaseCase
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. EndcaseEndwith
*** Add the Return for debugging
Return
.T.