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 of 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 data grids form type data grids with can be put into edit mode.

Using dgEditMode

This example stack uses a simple Data Grid form that displays the letters of the alphabet.

The code of the "Start Editing" button is

DGReorder *
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.

DGReorder *

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.

Setting "edit mode action select control" and "edit mode reorder control"

These properties can be set to the long of 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"
DGReorder *

Handling GetEditModeActionSelectControl and GetEditModeReorderControl

The GetEditModeActionSelectControl and GetEditModeReorderControl are sent to your data grid's custom row template when and action is selected. Handling then allows you to specify a custom action select 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

Directly edit the template controls

The third method is to directly edit the template controls, which are hidden groups your DataGrid template stack.

0 Comments

Add your comment

E-Mail me when someone replies to this comment