One thing I have done at run time is programmatically assign a 'celltype$ (such as Lookup, LookupHideBtn, Query, QueryHideBtn) to a grid cell. Then in the cell logic you can test for _EOM$=$FF$ to determine if the query or lookup button has been pressed and then do logic to invoke the query.