Using BINDEVENT to ease FoxPro Grid issues

BINDEVENT is one of those great FoxPro commands that you never think of until you need it but when you do, you really appreciate it and you’ll want to immediately refactor your code (hmmm- this sounds like a good Refactoring rule for the Code Analyst).

I was updating a client’s older VFP system that used a lot of grids with RightClick methods. Lots of older programs do the same thing: putting code directly into the rightclick method of each columns’ Text1 control. It’s a real pain later on – especially if you ever reset the recordsource (which rebuilds the columns from scratch). In addition, if you use Page Up and Page Down to scroll through the various pieces of code, you get to see each individual column’s method, which can get very tedious if you have a lot of grids.

Now, when you use BINDEVENT, it’s a lot less code and a lot easier to manage. I put the actual rightclick code into a method either on the form or grid and then just do:

FOR EACH loColumn IN THIS.Grid.Columns

When the user right-clicks in the grid, it calls the ColRightClick method.

Is this easier than putting THIS.ColRightClick() in each Text1 object? Maybe not if you only have two or three columns; but most of the grids I work with have lots of columns. Using this approach means I can keep my code OUT of the grid’s columns and accomplish this in only three lines of code.

1 thought on “Using BINDEVENT to ease FoxPro Grid issues”

Comments are closed.