LiveCode

LiveCode DataGrid Drag & Drop Reordering

I have a project where using a data grid form really simplifies things, however, it’s critical that the user can re-order the list in arbitrary way. To do this I needed to add drag and drop to the data grid.

First I wrote rolled my own:

There two main limitations with this code are that it will only work for a data grid form (not table) and only if the cache controls property is true.

<span class="entity entity_name entity_name_handler entity_name_handler_rev">local</span><span> sDragImage</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">,</span><span>sControlIndexMap</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">,</span><span>sOriginalIndexes</span>

<span class="storage storage_type storage_type_handler storage_type_handler_rev">on</span><span> dragStart</span>
<span>   </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">local</span><span> tControl</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">,</span><span>tItem</span>
<span>   </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">set</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> </span><span class="support support_command support_command_rev">dragData</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">[</span><span class="string string_quoted string_quoted_double string_quoted_double_transcript">"private"</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">]</span><span> </span><span class="keyword keyword_control keyword_control_rev">to</span><span> </span><span class="string string_quoted string_quoted_double string_quoted_double_transcript">"dgDragIndex"</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">&&</span><span class="keyword keyword_control keyword_control_rev">the</span><span> dgHilitedIndex </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">me</span>
<span>   </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">put</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> dgDataControlOfIndex</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">[</span><span class="keyword keyword_control keyword_control_rev">the</span><span> dgHilitedIndex </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">me</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">]</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">me</span><span> </span><span class="keyword keyword_control keyword_control_rev">into</span><span> tControl</span>
<span>   </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">lock</span><span> </span><span class="support support_command support_command_rev">screen</span>
<span>   </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">import</span><span> </span><span class="keyword keyword_control keyword_control_rev">snapshot</span><span> </span><span class="keyword keyword_control keyword_control_rev">from</span><span> tControl</span>
<span>   </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">put</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> </span><span class="support support_command support_command_rev">long</span><span> </span><span class="support support_command support_command_rev">id</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> </span><span class="keyword keyword_control keyword_control_rev">last</span><span> </span><span class="keyword keyword_control keyword_control_rev">image</span><span> </span><span class="keyword keyword_control keyword_control_rev">into</span><span> sDragImage</span>
<span>   </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">set</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> </span><span class="support support_command support_command_rev">visible</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> sDragImage </span><span class="keyword keyword_control keyword_control_rev">to</span><span> </span><span class="keyword keyword_control keyword_control_rev">false</span>
<span>   </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">set</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> </span><span class="support support_command support_command_rev">dragImage</span><span> </span><span class="keyword keyword_control keyword_control_rev">to</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> </span><span class="support support_command support_command_rev">short</span><span> </span><span class="support support_command support_command_rev">id</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> sDragImage</span>
<span>   </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">put</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> dgIndexes </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">me</span><span> </span><span class="keyword keyword_control keyword_control_rev">into</span><span> sOriginalIndexes</span>
<span>   </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">delete</span><span> </span><span class="keyword keyword_control keyword_control_rev">variable</span><span> sControlIndexMap</span>
<span>   </span><span class="keyword keyword_control keyword_control_rev">repeat</span><span> </span><span class="keyword keyword_control keyword_control_rev">for</span><span> </span><span class="keyword keyword_control keyword_control_rev">each</span><span> </span><span class="keyword keyword_control keyword_control_rev">item</span><span> tItem </span><span class="keyword keyword_control keyword_control_rev">in</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> dgIndexes </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">me</span>
<span>      </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">put</span><span> tItem </span><span class="keyword keyword_control keyword_control_rev">into</span><span> sControlIndexMap</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">[</span><span class="keyword keyword_control keyword_control_rev">the</span><span> dgDataControlOfIndex</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">[</span><span>tItem</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">]</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">me</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">]</span>
<span>   </span><span class="keyword keyword_control keyword_control_rev">end</span><span> </span><span class="keyword keyword_control keyword_control_rev">repeat</span>
<span>   </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">set</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> </span><span class="support support_command support_command_rev">allowableDragActions</span><span> </span><span class="keyword keyword_control keyword_control_rev">to</span><span> </span><span class="string string_quoted string_quoted_double string_quoted_double_transcript">"move"</span>
<span>   </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">pass</span><span> dragStart</span>
<span class="keyword keyword_control keyword_control_rev">end</span><span> dragStart</span>

<span class="storage storage_type storage_type_handler storage_type_handler_rev">on</span><span> dragMove pX</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">,</span><span>pY</span>
<span>   </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">local</span><span> tDragIndex</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">,</span><span>tNewIndexes</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">,</span><span>tOverIndex</span>
<span>   </span><span class="keyword keyword_control keyword_control_rev">if</span><span> </span><span class="keyword keyword_control keyword_control_rev">word</span><span> </span><span class="constant constant_numeric constant_numeric_rev">1</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> </span><span class="support support_command support_command_rev">dragData</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">[</span><span class="string string_quoted string_quoted_double string_quoted_double_transcript">"private"</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">]</span><span> </span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">=</span><span> </span><span class="string string_quoted string_quoted_double string_quoted_double_transcript">"dgDragIndex"</span><span> then</span>
<span>      </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">unlock</span><span> </span><span class="support support_command support_command_rev">screen</span>
<span>      </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">lock</span><span> </span><span class="support support_command support_command_rev">cursor</span><span> </span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_rev">-- refresh bug workaround on setting the dgIndexes the dragAction seems to get set to none</span>
<span>      </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">put</span><span> </span><span class="keyword keyword_control keyword_control_rev">word</span><span> </span><span class="constant constant_numeric constant_numeric_rev">2</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> </span><span class="support support_command support_command_rev">dragData</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">[</span><span class="string string_quoted string_quoted_double string_quoted_double_transcript">"private"</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">]</span><span> </span><span class="keyword keyword_control keyword_control_rev">into</span><span> tDragIndex</span>
<span>      </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">set</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> </span><span class="support support_command support_command_rev">dragAction</span><span> </span><span class="keyword keyword_control keyword_control_rev">to</span><span> </span><span class="string string_quoted string_quoted_double string_quoted_double_transcript">"move"</span>
<span>      </span><span class="keyword keyword_control keyword_control_rev">if</span><span> pY </span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">></span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> </span><span class="support support_command support_command_rev">bottom</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">me</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">-</span><span class="constant constant_numeric constant_numeric_rev">20</span><span> then</span>
<span>         </span><span class="keyword keyword_control keyword_control_rev">if</span><span> </span><span class="keyword keyword_control keyword_control_rev">item</span><span> </span><span class="constant constant_numeric constant_numeric_rev">2</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> dgVisibleLines </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">me</span><span> </span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev"><</span><span>  </span><span class="keyword keyword_control keyword_control_rev">the</span><span> dgNumberOfLines </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">me</span><span> </span><span class="keyword keyword_control keyword_control_rev">or</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> </span><span class="support support_command support_command_rev">scroll</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">me</span><span> </span><span class="keyword keyword_control keyword_control_rev">is</span><span> </span><span class="keyword keyword_control keyword_control_rev">not</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> dgFormattedHeight </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">me</span><span> then </span>
<span>            </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">set</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> dgVscroll </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">me</span><span> </span><span class="keyword keyword_control keyword_control_rev">to</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">min</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">(</span><span class="keyword keyword_control keyword_control_rev">the</span><span> dgVscroll </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">me</span><span> </span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">+</span><span> </span><span class="constant constant_numeric constant_numeric_rev">20</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">,</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> dgFormattedHeight </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">me</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">)</span>
<span>         </span><span class="keyword keyword_control keyword_control_rev">end</span><span> </span><span class="keyword keyword_control keyword_control_rev">if</span>
<span>      </span><span class="keyword keyword_control keyword_control_rev">else</span><span> </span><span class="keyword keyword_control keyword_control_rev">if</span><span>  pY </span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev"><</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> </span><span class="support support_command support_command_rev">top</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">me</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">+</span><span class="constant constant_numeric constant_numeric_rev">20</span><span> then</span>
<span>         </span><span class="keyword keyword_control keyword_control_rev">if</span><span> </span><span class="keyword keyword_control keyword_control_rev">item</span><span> </span><span class="constant constant_numeric constant_numeric_rev">1</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> dgVisibleLines </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">me</span><span> </span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">></span><span>  </span><span class="constant constant_numeric constant_numeric_rev">1</span><span> </span><span class="keyword keyword_control keyword_control_rev">or</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> </span><span class="support support_command support_command_rev">scroll</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">me</span><span> </span><span class="keyword keyword_control keyword_control_rev">is</span><span> </span><span class="keyword keyword_control keyword_control_rev">not</span><span> </span><span class="constant constant_numeric constant_numeric_rev">0</span><span> then </span>
<span>            </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">set</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> dgVscroll </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">me</span><span> </span><span class="keyword keyword_control keyword_control_rev">to</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">max</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">(</span><span class="keyword keyword_control keyword_control_rev">the</span><span> dgVscroll </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">me</span><span> </span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">-</span><span> </span><span class="constant constant_numeric constant_numeric_rev">20</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">,</span><span class="constant constant_numeric constant_numeric_rev">0</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">)</span>
<span>         </span><span class="keyword keyword_control keyword_control_rev">end</span><span> </span><span class="keyword keyword_control keyword_control_rev">if</span>
<span>      </span><span class="keyword keyword_control keyword_control_rev">end</span><span> </span><span class="keyword keyword_control keyword_control_rev">if</span>
<span>      </span><span class="keyword keyword_control keyword_control_rev">repeat</span><span> </span><span class="keyword keyword_control keyword_control_rev">with</span><span> X</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">=</span><span class="constant constant_numeric constant_numeric_rev">1</span><span> </span><span class="keyword keyword_control keyword_control_rev">to</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> </span><span class="support support_command support_command_rev">number</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="keyword keyword_control keyword_control_rev">groups</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">group</span><span> </span><span class="string string_quoted string_quoted_double string_quoted_double_transcript">"dgList"</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">me</span>
<span>         </span><span class="keyword keyword_control keyword_control_rev">if</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> </span><span class="support support_command support_command_rev">visible</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">group</span><span> X </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">group</span><span> </span><span class="string string_quoted string_quoted_double string_quoted_double_transcript">"dgList"</span><span> </span><span class="keyword keyword_control keyword_control_rev">and</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> </span><span class="support support_command support_command_rev">short</span><span> </span><span class="support support_command support_command_rev">name</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">owner</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">group</span><span> X </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">group</span><span> </span><span class="string string_quoted string_quoted_double string_quoted_double_transcript">"dgList"</span><span> </span><span class="keyword keyword_control keyword_control_rev">is</span><span> </span><span class="string string_quoted string_quoted_double string_quoted_double_transcript">"dgList"</span><span> then</span>
<span>            </span><span class="keyword keyword_control keyword_control_rev">if</span><span> </span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">(</span><span>pY </span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">>=</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> </span><span class="support support_command support_command_rev">top</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">group</span><span> X </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">group</span><span> </span><span class="string string_quoted string_quoted_double string_quoted_double_transcript">"dgList"</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">me</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">)</span><span> </span><span class="keyword keyword_control keyword_control_rev">and</span><span> </span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">(</span><span>pY </span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev"><</span><span> </span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">(</span><span class="keyword keyword_control keyword_control_rev">the</span><span> </span><span class="support support_command support_command_rev">top</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">group</span><span> X </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">group</span><span> </span><span class="string string_quoted string_quoted_double string_quoted_double_transcript">"dgList"</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">me</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">+(</span><span class="keyword keyword_control keyword_control_rev">the</span><span> </span><span class="support support_command support_command_rev">bottom</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">group</span><span> X </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">group</span><span> </span><span class="string string_quoted string_quoted_double string_quoted_double_transcript">"dgList"</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">me</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">-</span><span class="keyword keyword_control keyword_control_rev">the</span><span> </span><span class="support support_command support_command_rev">top</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">group</span><span> X </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">group</span><span> </span><span class="string string_quoted string_quoted_double string_quoted_double_transcript">"dgList"</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">me</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">)</span><span> </span><span class="keyword keyword_control keyword_control_rev">div</span><span> </span><span class="constant constant_numeric constant_numeric_rev">2</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">))</span><span> then</span>
<span>               </span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_rev">-- place above index</span>
<span>               </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">put</span><span> sControlIndexMap</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">[</span><span class="keyword keyword_control keyword_control_rev">the</span><span> </span><span class="support support_command support_command_rev">long</span><span> </span><span class="support support_command support_command_rev">id</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">group</span><span> X </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">group</span><span> </span><span class="string string_quoted string_quoted_double string_quoted_double_transcript">"dgList"</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">me</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">]</span><span> </span><span class="keyword keyword_control keyword_control_rev">into</span><span> tOverIndex</span>
<span>               </span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_rev">--put "over"&&tOverIndex</span>
<span>               </span><span class="keyword keyword_control keyword_control_rev">if</span><span> tDragIndex </span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">=</span><span> tOverIndex then </span>
<span>                  </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">put</span><span> sOriginalIndexes </span><span class="keyword keyword_control keyword_control_rev">into</span><span> tNewIndexes</span>
<span>               </span><span class="keyword keyword_control keyword_control_rev">else</span>
<span>                  </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">put</span><span> sOriginalIndexes </span><span class="keyword keyword_control keyword_control_rev">into</span><span> tNewIndexes</span>
<span>                  </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">delete</span><span> </span><span class="keyword keyword_control keyword_control_rev">item</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">itemOffset</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">(</span><span>tDragIndex</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">,</span><span>tNewIndexes</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">)</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> tNewIndexes</span>
<span>                  </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">put</span><span> tDragIndex</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">&</span><span class="string string_quoted string_quoted_double string_quoted_double_transcript">","</span><span> </span><span class="keyword keyword_control keyword_control_rev">before</span><span> </span><span class="keyword keyword_control keyword_control_rev">item</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">itemOffset</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">(</span><span>tOverIndex</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">,</span><span>tNewIndexes</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">)</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> tNewIndexes</span>
<span>               </span><span class="keyword keyword_control keyword_control_rev">end</span><span> </span><span class="keyword keyword_control keyword_control_rev">if</span>
<span>               </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">set</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> dgIndexes </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">me</span><span> </span><span class="keyword keyword_control keyword_control_rev">to</span><span> tNewIndexes</span>
<span>               </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">put</span><span> tNewIndexes </span><span class="keyword keyword_control keyword_control_rev">into</span><span> sOriginalIndexes</span>
<span>            </span><span class="keyword keyword_control keyword_control_rev">else</span><span> </span><span class="keyword keyword_control keyword_control_rev">if</span><span> </span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">(</span><span>pY </span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev"><=</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> </span><span class="support support_command support_command_rev">bottom</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">group</span><span> X </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">group</span><span> </span><span class="string string_quoted string_quoted_double string_quoted_double_transcript">"dgList"</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">me</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">)</span><span> </span><span class="keyword keyword_control keyword_control_rev">and</span><span> </span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">(</span><span>pY </span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">></span><span> </span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">(</span><span class="keyword keyword_control keyword_control_rev">the</span><span> </span><span class="support support_command support_command_rev">top</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">group</span><span> X </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">group</span><span> </span><span class="string string_quoted string_quoted_double string_quoted_double_transcript">"dgList"</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">me</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">+(</span><span class="keyword keyword_control keyword_control_rev">the</span><span> </span><span class="support support_command support_command_rev">bottom</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">group</span><span> X </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">group</span><span> </span><span class="string string_quoted string_quoted_double string_quoted_double_transcript">"dgList"</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">me</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">-</span><span class="keyword keyword_control keyword_control_rev">the</span><span> </span><span class="support support_command support_command_rev">top</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">group</span><span> X </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">group</span><span> </span><span class="string string_quoted string_quoted_double string_quoted_double_transcript">"dgList"</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">me</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">)</span><span> </span><span class="keyword keyword_control keyword_control_rev">div</span><span> </span><span class="constant constant_numeric constant_numeric_rev">2</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">))</span><span> then</span>
<span>               </span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_rev">-- place below index</span>
<span>               </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">put</span><span> sControlIndexMap</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">[</span><span class="keyword keyword_control keyword_control_rev">the</span><span> </span><span class="support support_command support_command_rev">long</span><span> </span><span class="support support_command support_command_rev">id</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">group</span><span> X </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">group</span><span> </span><span class="string string_quoted string_quoted_double string_quoted_double_transcript">"dgList"</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">me</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">]</span><span> </span><span class="keyword keyword_control keyword_control_rev">into</span><span> tOverIndex</span>
<span>               </span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_rev">--put "over"&&tOverIndex</span>
<span>               </span><span class="keyword keyword_control keyword_control_rev">if</span><span> tDragIndex </span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">=</span><span> tOverIndex then </span>
<span>                  </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">put</span><span> sOriginalIndexes </span><span class="keyword keyword_control keyword_control_rev">into</span><span> tNewIndexes</span>
<span>               </span><span class="keyword keyword_control keyword_control_rev">else</span>
<span>                  </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">put</span><span> sOriginalIndexes </span><span class="keyword keyword_control keyword_control_rev">into</span><span> tNewIndexes</span>
<span>                  </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">delete</span><span> </span><span class="keyword keyword_control keyword_control_rev">item</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">itemOffset</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">(</span><span>tDragIndex</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">,</span><span>tNewIndexes</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">)</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> tNewIndexes</span>
<span>                  </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">put</span><span> </span><span class="string string_quoted string_quoted_double string_quoted_double_transcript">","</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">&</span><span>tDragIndex </span><span class="keyword keyword_control keyword_control_rev">after</span><span> </span><span class="keyword keyword_control keyword_control_rev">item</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">itemOffset</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">(</span><span>tOverIndex</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">,</span><span>tNewIndexes</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">)</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> tNewIndexes</span>
<span>               </span><span class="keyword keyword_control keyword_control_rev">end</span><span> </span><span class="keyword keyword_control keyword_control_rev">if</span>
<span>               </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">set</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> dgIndexes </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">me</span><span> </span><span class="keyword keyword_control keyword_control_rev">to</span><span> tNewIndexes</span>
<span>               </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">put</span><span> tNewIndexes </span><span class="keyword keyword_control keyword_control_rev">into</span><span> sOriginalIndexes</span>
<span>            </span><span class="keyword keyword_control keyword_control_rev">end</span><span> </span><span class="keyword keyword_control keyword_control_rev">if</span>
<span>         </span><span class="keyword keyword_control keyword_control_rev">end</span><span> </span><span class="keyword keyword_control keyword_control_rev">if</span>
<span>      </span><span class="keyword keyword_control keyword_control_rev">end</span><span> </span><span class="keyword keyword_control keyword_control_rev">repeat</span>
<span>   </span><span class="keyword keyword_control keyword_control_rev">end</span><span> </span><span class="keyword keyword_control keyword_control_rev">if</span>
<span>   </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">pass</span><span> dragMove</span>
<span class="keyword keyword_control keyword_control_rev">end</span><span> dragMove</span>

<span class="storage storage_type storage_type_handler storage_type_handler_rev">on</span><span> dragEnd</span>
<span>   </span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_rev">-- clean up</span>
<span>   </span><span class="keyword keyword_control keyword_control_rev">if</span><span> sDragImage </span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev"><></span><span> </span><span class="string string_quoted string_quoted_double string_quoted_double_transcript">""</span><span> then</span>
<span>      </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">delete</span><span> sDragImage</span>
<span>      </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">put</span><span> </span><span class="string string_quoted string_quoted_double string_quoted_double_transcript">""</span><span> </span><span class="keyword keyword_control keyword_control_rev">into</span><span> sDragImage</span>
<span>   </span><span class="keyword keyword_control keyword_control_rev">end</span><span> </span><span class="keyword keyword_control keyword_control_rev">if</span>
<span>   </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">pass</span><span> dragEnd</span>
<span class="keyword keyword_control keyword_control_rev">end</span><span> dragEnd</span>

Then I had a poke around the data grid behavior script and found undocumented support for drag and drop. So here’s the new script that does not have the limitations of the above and is obviously far less verbose:

<span class="storage storage_type storage_type_handler storage_type_handler_rev">on</span><span> dragStart</span>
<span>   </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">local</span><span> tIndex</span>
<span>   </span><span class="keyword keyword_control keyword_control_rev">if</span><span> </span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">(</span><span class="keyword keyword_control keyword_control_rev">the</span><span> dgHeader </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">target</span><span> </span><span class="keyword keyword_control keyword_control_rev">is</span><span> </span><span class="keyword keyword_control keyword_control_rev">empty</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">)</span><span> then</span>
<span>      </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">put</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> dgIndex </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> dgDataControl </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">target</span><span> </span><span class="keyword keyword_control keyword_control_rev">into</span><span> tIndex</span>
<span>      </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">set</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> dgDragImageIndex </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">me</span><span> </span><span class="keyword keyword_control keyword_control_rev">to</span><span> tIndex</span>
<span>      </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">set</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> </span><span class="support support_command support_command_rev">dragData</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">[</span><span class="string string_quoted string_quoted_double string_quoted_double_transcript">"private"</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">]</span><span> </span><span class="keyword keyword_control keyword_control_rev">to</span><span> </span><span class="keyword keyword_control keyword_control_rev">empty</span>
<span>      </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">set</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> dgTrackDragReorder</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">[</span><span>tIndex</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">]</span><span> </span><span class="keyword keyword_control keyword_control_rev">of</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">me</span><span> </span><span class="keyword keyword_control keyword_control_rev">to</span><span> </span><span class="keyword keyword_control keyword_control_rev">true</span>
<span>   </span><span class="keyword keyword_control keyword_control_rev">end</span><span> </span><span class="keyword keyword_control keyword_control_rev">if</span>
<span class="keyword keyword_control keyword_control_rev">end</span><span> dragStart</span>

<span class="storage storage_type storage_type_handler storage_type_handler_rev">on</span><span> DragReorderDrop pOriginatingIndex</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">,</span><span> pStartLine</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">,</span><span> pDroppedOnLine</span>
<span>   </span><span class="keyword keyword_control keyword_control_rev">if</span><span> </span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">(</span><span>pStartLine </span><span class="keyword keyword_control keyword_control_rev">is</span><span> </span><span class="keyword keyword_control keyword_control_rev">not</span><span> pDroppedOnLine</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">)</span><span> then</span>
<span>      SetLineOfIndex pOriginatingIndex</span><span class="keyword keyword_operator keyword_operator_symbolic keyword_operator_symbolic_rev">,</span><span> pDroppedOnLine</span>
<span>      </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">send</span><span> </span><span class="string string_quoted string_quoted_double string_quoted_double_transcript">"RefreshList"</span><span> </span><span class="keyword keyword_control keyword_control_rev">to</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">me</span><span> </span><span class="keyword keyword_control keyword_control_rev">in</span><span> </span><span class="constant constant_numeric constant_numeric_rev">0</span><span> </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">secs</span>
<span>   </span><span class="keyword keyword_control keyword_control_rev">end</span><span> </span><span class="keyword keyword_control keyword_control_rev">if</span>
<span class="keyword keyword_control keyword_control_rev">end</span><span> DragReorderDrop</span>

<span class="storage storage_type storage_type_handler storage_type_handler_rev">on</span><span> dragMove</span>
<span>   </span><span class="entity entity_name entity_name_handler entity_name_handler_rev">set</span><span> </span><span class="keyword keyword_control keyword_control_rev">the</span><span> </span><span class="support support_command support_command_rev">dragaction</span><span> </span><span class="keyword keyword_control keyword_control_rev">to</span><span> </span><span class="string string_quoted string_quoted_double string_quoted_double_transcript">"move"</span>
<span class="keyword keyword_control keyword_control_rev">end</span><span> dragMove</span>