How do I reorder rows in a Data Grid?
This lesson will show you how to use the Data Grid Edit mode for Data Grid forms.
The dgEdit Mode
Setting the dgEditMode property of a Data Grid to true will put the Data Grid into edit mode, setting it to false will take it out of edit mode.
When a Data Grid is in edit mode, the Data Grid displays an action control on the left hand side of each row and a reorder control on the right. The appearance and behavior of these controls can be customized.
Only form type Data Grids can be put into edit mode.
This example stack uses a simple Data Grid form that displays the letters of the alphabet.
The code of the "Start Editing" button is
on mouseUp set the dgEditMode of group "Alphabet" to true end mouseUp
The code of the "Stop Editing" button is
on mouseUp set the dgEditMode of group "Alphabet" to false end mouseUp
Click "Start Editing" to put the Data Grid into Edit mode. You can then use the reorder control on the right to reorder the rows.
Click "Stop Editing" to take the Data Grid out of Edit mode.
Customizing the Edit mode options
There are 3 ways to customize the controls shown when the Data Grid is in Edit mode.
1. Setting "edit mode action select control" and "edit mode reorder control" properties
These properties can be set to the long ID of an object or empty.
Setting the "edit mode action select control" will change the control that appears on the left, setting the "edit mode reorder control" will change the control on the right. Setting either of these properties to empty will result in the control not being displayed.
set the dgProps["edit mode action select control"] of group "Alphabet" to the long id of widget "star"
2. Handling GetEditModeActionSelectControl and GetEditModeReorderControl messages
The GetEditModeActionSelectControl and GetEditModeReorderControl messages are sent to the data grid's custom row template when an action is selected. Handling these messages allows you to specify a control by returning the ID of the control you want to display. Returning empty will result in no control being displayed.
on GetEditModeActionSelectControl return empty end GetEditModeActionSelectControl
You can also use this method to prevent the reordering of certain rows. For example:
on GetEditModeReorderControl if the dgIndex of me is 5 then return empty end if pass GetEditModeReorderControl end GetEditModeReorderControl
3. Directly edit the template controls
The third method is to directly edit the template controls, which are hidden groups your DataGrid template stack.