How Do I Display a Contextual Menu When the User Clicks on a Column Header?
This lesson will show you how to display a contextual menu (1) when the user clicks on a column header in a Data Grid table (2).
Let's look at some RevTalk code that will display a contextual menu. The code is located in the Data Grid group script.
A contextual menu is displayed when during the mouseDown message when the user clicks with the right mouse button (1).
To determine if the user clicked on a column header you can check whether or not the dgHeaderControl property of the control that was clicked on (the target) is empty (2). If the property is not empty then you know that the user clicked on a column header.
Once you know that the user clicked on a column header you can display the contextual menu. In this example I take the name of the column that was clicked on (3) and append " Popup" to it in order to get the name of the popup button to display (4).
Copy & Paste
on mouseDown pBtnNum ## Let Data Grid process mouseDown dgMouseDown pBtnNum if pBtnNum is 3 then if the dgHeaderControl of the target is not empty then ## the user clicked on a column header ## Get column name put the dgColumn of the target into theColumn ## Get name of contextual button to use put theColumn && "Popup" into theContextualButtonName ## Display contextual if exists if there is a button theContextualButtonName then popup button theContextualButtonName end if end if end if end mouseDown
Now when I right-click on the State column the State Popup popup button is displayed as a contextual menu.