Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grids ¦ Enabling Delete only when items are marked?

Status
Not open for further replies.

DJVisuaL

Programmer
May 31, 2000
52
US
I have a "delete" command button that basically calls PACK and deletes marked Grid items...
I want "delete" to only be enabled when there are items marked in the Grid
the delete grid event lets you know when an Item is marked or unmarked but how do you tell which?
right now If no grid items are marked and the user marks a grid item and then unmarks it... my delete button is enabled each time they click...
how can I tell if there are no marked grid items?

TY
DJ

I tryed this in the delete event but it didnt work...

LPARAMETERS nRecNo
GOTO nRecNo
IIF(DELETED(),thisform.bDelete.Enabled=.T.,thisform.bDelete.Enabled=.F.)
 
DJVisual

This is untried but...

* Delete event
LPARAMETERS nRecNo
lnRecNo = RECNO()
COUNT FOR DELETED() to lnCount
GOTO lnRecNo

IF lnCount > 0
[tab]THISFORM.bDelete.Enabled=.T.
ELSE
[tab]THISFORM.bDelete.Enabled=.F.
ENDIF

Using a checkbox for selection may give you more scope

Chris
 
hmmmmmm
doesn't work
I traced through it and to me it looks like the Deleted event occurs before the record is marked for deletion and the record is marked on the grid
so the COUNT will work if there is more than one record marked but not if there is only 1..
*so confused now*
I guess I giveup on this one LoL *shrugs* why would they put an event that occurs before the delete? grrrrrr
 
For simplicity's sake, I put all the code into the Deleted event of the grid:

PROCEDURE GRID.DELETED()
LPARAMETERS nRecNo

COUNT FOR DELETED() to lnCount
GOTO nRecNo

*User is toggling the deletion mark
lnDeleted=lnCount+IIF(deleted(),-1,1)

THISFORM.bDelete.ENABLED=(lnDeleted>0)
ENDPROC

You could (and IMO, should) normalize this by making lnDeleted a property of the grid (or form if the grid isnt a subclass) and placing bDelete.Enabled=(lnDeleted>0) in the refresh event of the button.

PROCEDURE GRID.DELETED()
LPARAMETERS nRecNo

COUNT FOR DELETED() to lnCount
GOTO nRecNo

*User is toggling the deletion mark
THIS.inDeleted=lnCount+IIF(deleted(),-1,1)

THISFORM.Refresh()
ENDPROC

PROCEDURE bDeleted.REFRESH()
THIS.ENABLED=(THISFORM.Grid.inDeleted>0)
ENDPROC
 
OK Thanks =)
After playing awhile I ended up with code to the same effect as yours except I didn't GOTO nRecNo!? Does COUNT move the record pointer when it counts?
not sure why you have to GOTO nRecNo but it works wohoo!

DJ
 
DJVisual

Glad Jon Hawkins was able to help.

If you COUNT TO lnCount, you will find EOF() = .T.

Chris
 
Thanks Chris!
I'm still learning wasn't aware of EOF()
Why do I feel like I am cheating when I use VFP?
It is a well thought out language IMHO...
I can't wait to master it (if possible) LoL
DJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top