[Expand]General Information
[Collapse]WinForms Controls
  .NET Core Support
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications, and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Collapse]Vertical Grid
   [Expand]Binding to Data
   [Expand]Data Layout: Records, Rows and Cells
   [Expand]Data Editing and Validation
    Formatting Values
   [Collapse]Drag and Drop
    [Collapse]OLE Drag and Drop Overview
      VerticalGrid as the Source of Drag and Drop
      VerticalGrid as the Target of Drag and Drop
     Dragging Rows
   [Expand]Appearance and Custom Painting
   [Expand]Visual Elements
   [Expand]Design-Time Features
   [Expand]End-User Capabilities
    Hit Information
    Batch Modifications
   [Expand]Member Tables
  [Expand]Property Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Gantt Control
  [Expand]Chart Control
  [Expand]Map Control
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Sunburst Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

VerticalGrid as the Target of Drag and Drop

This topic shows how to customize a vertical grid control so it can serve as a target for OLE drag and drop operations. You can use this topic's code sample to apply styles to individual rows using drag and drop. A general overview for implementing OLE drag and drop can be found in OLE Drag and Drop Overview.

Expanded Dragging Styles to Rows of the Vertical Grid. Detailed Description

The sample in this topic involves the customization of two controls. A list box control will serve as the drag and drop source, the VGridControl will accept the dragged values. Actually, this sample performs the following tasks.

  • Creates and customizes two appearances (AppearanceObject objects).
  • Adds two items to the list box control that is the drag and drop source. Item captions must be the same as appearance names.
  • Performs custom painting of items in the list box.
  • Customizes the list box to be the OLE drag and drop source. Specify item captions as the drag data.
  • Customizes the vertical grid control to be the target for OLE Drag and Drop operations. Allows dropping only onto row headers or cells. The appearance whose name is specified by the drag data must be used to paint the target row.

The grid's styles can be initialized together with list box control items. This can be performed in the form's Load event handler as demonstrated in the code below. Note that the list box control's DrawMode property is set to DrawMode.OwnerDrawVariable to force the control to use the MeasureItem and DrawItem events to specify the size of its items and paint them. Also, you need to set the vertical grid control's AllowDrop property to true to allow dropping onto the control.

The next step is to specify the size of items and paint them using the defined styles. The list box's MeasureItem and DrawItem events are used for this purpose. The MeasureItem event handler sets the processed item's height to the height of the "Style Sample" string if it was painted using the font set by the corresponding style. The DrawItem event handler paints the processed item using the corresponding style's settings.

Now you need to customize the list box to make it the source for drag and drop operations. This will be performed in the MouseDown event handler. It will check whether the mouse cursor is currently over an item and if so, dragging will be initialized using the DoDragDrop method call. The item's caption (that is the same as the corresponding style name) will then be passed to this method as the data to be dragged. See the code below.

One more thing to be done is to handle the dragging process. This implies handling the DragOver event of the vertical grid control. The handler will determine whether a row header or a cell is located underneath the mouse pointer and if so, it will allow dropping. Note that you must use the VGridControlBase.CalcHitInfo method to determine which element is at the specified point. Please refer to the Obtain Hit Information topic for details on using this method.

The code below demonstrates how the dragging process is handled.

The last thing to complete the sample is to handle dropping. This involves writing a handler for the DragDrop event of the vertical grid. The handler determines the row located underneath the mouse pointer and assigns the dragged style to it. The BaseRow.StyleName property is used to specify row style. See the code below.

Expanded Dragging Styles to Rows of the Vertical Grid. The Complete Code

The entire code required by your application to implement dragging styles from a list box to vertical grid rows is listed below:

The image below shows the appearance of the list box and the vertical grid control as well as illustrating how dragging can be performed between them.

Is this topic helpful?​​​​​​​