ObjectListView and Drag & Drop - ObjectListView v2.6
ObjectListView and Drag & Drop - ObjectListView v2.6
ObjectListView and Drag & Drop - ObjectListView v2.6
If you set IsSimpleDragSource to true, the ObjectListView will be able to initiate drags. It will drag the currently selected items, as well as creating text and HTML versions of those rows that can be dropped onto other programs. If you set IsSimpleDropSink to true, the ObjectListView will be able to receive drops. The normal drop sink does a lot of work for you: figuring out which item is under the mouse, handling auto scrolling, drawing user feedback. However, there are two things that it cant figure out for itself: 1. Are the dragged objects allowed to be dropped at the current point? 2. What should happen when the drop occurs? So, the normal drop sink triggers two events: CanDrop and Dropped. To actually be useful, you need to handle these events. You can set up handlers for these events within the IDE, like normal. You can alternatively listen for the ModelCanDrop and ModelDropped events. This second pair of events are triggered when the source of the drag is another ObjectListView. These events work the same as the CanDrop and Dropped events except that the argument block includes useful information: The ObjectListView initiated the drag The model objects are being dragged The model object is current target of the drop
http://objectlistview.sourceforge.net/cs/dragdrop.html#dragdrop-label
1/5
28/11/2013
Inside the CanDrop handler, you can set the InfoMessage property to a string. If you do this, the string will be shown to the user while they are dragging. This can be used to tell the user why something cannot be dropped at that particular point, or to explain what will happen if the drop occured there:
This message is displayed by a specialised TextOverlay, which is exposed through the Billboard property of the SimpleDropSink class. You can make changes to the messages appearance through this property.
The ModelDropped event has a convenience method, RefreshObjects(), which refreshes all the objects involved in the
http://objectlistview.sourceforge.net/cs/dragdrop.html#dragdrop-label 2/5
28/11/2013
SimpleDataSource
The major task of the SimpleDataSource is to setup a DataObject which can be used for dragging and dropping. If you want your ObjectListView to support other data formats, you will need subclass SimpleDataSource and add the data formats you want.
SimpleDropSink
SimpleDropSink is a lot more interesting and a lot more configurable. It can be made to accept drops between items:
m y D r o p S i n k . C a n D r o p B e t w e e n=t r u e ;
http://objectlistview.sourceforge.net/cs/dragdrop.html#dragdrop-label
3/5
28/11/2013
It can also change the color used for the drag drop feedback:
m y D r o p S i n k . F e e d b a c k C o l o r=C o l o r . I n d i a n R e d ;
The only new method in this list is the DrawFeedback() method. This is where the DropSink can draw feedback onto the ObjectListView to indicate the state of the drop. This drawing is done over the top of the ObjectListView and this will normally involve some form of alpha blending. In almost all cases, you can subclass AbstractDropSink which provides minimal implementations of all these methods.
http://objectlistview.sourceforge.net/cs/dragdrop.html#dragdrop-label
4/5
28/11/2013
This turns objectListView1 into a rearrangeble list, where the user can rearrange the rows by dragging them. The false parameter says that this sink will not accept drags from other ObjectListViews. The class is clever but it is not magical. It works even when the ObjectListView is sorted or grouped, but it is up to the programmer to decide what rearranging such lists means. Example: if the control is grouping students by academic grade, and the user drags a Fail grade student into the A+ group, it is the responsibility of the programmer to makes the appropriate changes to the model and redraw/rebuild the control so that the users action makes sense. Similarly, it is up to the programmer to decide what should happen if the user rearranges rows when the list is sorted. It also cannot work on DataListView, VirtualObjectListView and TreeListViews since the data in those control is outside the control of the ObjectListView. For those controls, you will have to use (or subclass) a SimpleDropSink and do the actual rearranging and refreshing yourself. See this blog for a detailed discussion of how to make a rearrangeable TreeListView.
Copyright 2006-2012, Phillip Piper. Last updated on Oct 30, 2012. Created using Sphinx 1.0.7.
http://objectlistview.sourceforge.net/cs/dragdrop.html#dragdrop-label
5/5