Image of Navigational Map linked to Home / Contents / Search What a Drag

by Stephan Grieger - Independent Developer
Image of Line Break

This small code sample takes a grid in the form of fields and allows you to re-arrange the rows by dragging them to the new location. However, unlike other drag methods using fields, we are not going to actually drag the fields using the Drag methods of controls.

The effect is exactly the same as that of the task manager in Outlook. When you select one of the rows in Outlook, and then move the mouse, the row is highlighted and a line appears informing you of where the row will be moved to.

The code sample I have provided will swap the two fields around. However, it wouldn't take a lot to make it a move instead of a swap. The code is in VB 5.0 format. If you do not have VB 5 then you can copy the code out using something like notepad. You will then need to place a number of text boxes on the form, each directly under the other. They should also be a control array. You also need to image controls with arrows in them which make up the line.

As an extra to the code comments, the ReleaseCapture API does exactly that. When you click on a control, that control then takes control of all the mouse events like MouseMove etc. When we move over another control, we want to be able to tell which control we moved over. In order to be able to determine that, we need to be able to trap the MouseMove event on the other controls. So, when we click on the control, we call the ReleaseCapture API which then basically releases that control's control over the mouse events.

I've included the code in the downloadable ZIP. Enjoy!



Written by: Stephen Grieger
January '98

Image of Arrow linked to Previous Article
Image of Line Break
[HOME] [TABLE OF CONTENTS] [SEARCH]