HOME PAGE | DOWNLOAD | TUTORIALS | XtraReports
Devexpress

Thursday, July 19, 2012

Controlling the Drag and Drop of the Column Headers

The XtraGrid invokes the DragObjectOver event whenever it needs to determine if a particular drag and drop operation is valid. For example to prevent a specific column from being moved to a customization form, we simply need to inspect the passed-in event args and set the DragInfo.Valid property to false.

1.       We have a sample project here with an XtraGrid control on a form.

2.       We’ll select the gridView1 and assign the DragObjectOver event handler.

3.       We will receive two values in the event args. DragObject and DropInfo.

4.       DragObject represents the object that is currently being dragged on the grid’s surface, and the DropInfo contains additional positioning information like drag bounds and the Index of the DragObject as it relates to the grid control.

5.       By examining the DropInfo.Index property, we can determine what drag and drop operation is currently being performed.

6.       For example the Index property will be set to a positive value if a grouping or a re-ordering operation is being done. And, it is set to a negative value -100 if a column is being removed from the header or to -101 if it is being moved to a customization window.

7.       In this case we are interested in when the column is being moved to a customization form so we will set the DropInfo.Value to false if DropInfo.Index is -101

private void gridView1_DragObjectOver(object sender, DragObjectOverEventArgs e) {

GridColumn column = e.DragObject as GridColumn;

       if (column != null) {

              if (e.DropInfo.Index == -101) {

                     e.DropInfo.Valid = false;

              }

       }

}

 

8.       Now, the customization form will not accept any column headers that are being dragged onto it.

 

 

No comments:

Post a Comment