ItemPanel control supports automatic drag & drop operations with no code required on your part when EnableDragDrop property is set to true.

When you want to customize drag & drop behavior to say disable the drag & drop for certain positions inside of ItemPanel you would do that in following way:

  1. Set ItemPanel.AllowDrop=true to enable Windows Forms drag & drop support
  2. Set ItemPanel.EnableDragDrop=true to enable ItemPanel internal drag & drop support which provides insertion markers etc.
  3. Set ItemPanel.UseNativeDragDrop=true to indicate that ItemPanel should use Windows Forms drag & drop.
  4. Handle ItemPanel.DragOver event. Here you can disable the drop operation by setting DragEventArgs.Effect=None under any conditions you wish such as current mouse position etc.
  5. To start drag & drop operation for a button in ItemPanel use ItemPanel.StartItemDrag(myButton) method. You would usually do this from MouseMove event when left mouse button is pressed and cursor has moved to indicate the drag & drop.

After user has completed drag & drop operation the ItemPanel.UserCustomize event will be fired. You would check the type of the sender argument in event handler and if it is an BaseItem type that would give you the reference to the instance of item that was dropped. BaseItem.Parent returns then new parent and BaseItem.Parent.SubItems.IndexOf method can be used to find the new index for the item.

To accept the external items (of type BaseItem) into the ItemPanel you would set ItemPanel.AllowExternalDrop property to true.