Back to Devexpress

GridView.DragObjectOver Event

windowsforms-devexpress-dot-xtragrid-dot-views-dot-grid-dot-gridview-9360c212.md

latest4.9 KB
Original Source

GridView.DragObjectOver Event

Enables you to control whether the dragged column header or band header can be dropped at the current position.

Namespace : DevExpress.XtraGrid.Views.Grid

Assembly : DevExpress.XtraGrid.v25.2.dll

NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation

Declaration

csharp
[DXCategory("DragDrop")]
public event DragObjectOverEventHandler DragObjectOver
vb
<DXCategory("DragDrop")>
Public Event DragObjectOver As DragObjectOverEventHandler

Event Data

The DragObjectOver event's data class is DragObjectOverEventArgs. The following properties provide information specific to this event:

PropertyDescription
DragObjectGets the column or band whose header is being dragged.
DropInfoGets an object containing information about the dragged header’s current position.

Remarks

The DragObjectOver event fires repeatedly when dragging a column or band header. This event lets you prevent dropping at the current position.

Use the event’s DragObjectOverEventArgs.DragObject and DragObjectOverEventArgs.DropInfo parameters to identify the element being dragged and to obtain its current position. To prevent dropping, set the Valid property of the DragObjectOverEventArgs.DropInfo object to false. This forces the View to ignore a subsequent drop of the dragged object.

Note that the GridView.DragObjectDrop event occurs regardless of the operation’s result. Its DragObjectDropEventArgs.Canceled parameter will be set to false if the drag and drop operation was canceled.

For general information on handling column and band header dragging, see the GridView.DragObjectStart topic.

Example

The example shows how to prevent moving the “ContactName” column to the Customization Form.

To control drag-and-drop of grid columns, we handle the GridView.DragObjectOver event. The DragObjectOverEventArgs.DropInfo event’s parameter contains information on the current position where drag-and-drop will occur if the end-user drops the drag object. The Index property of the DragObjectOverEventArgs.DropInfo would be -1 when dragging over the Customization Form.

csharp
using DevExpress.XtraGrid.Views.Base;

private void bandedGridView1_DragObjectOver(object sender, DragObjectOverEventArgs e) {
    GridColumn column = e.DragObject as GridColumn;
    if (column != null) {
        e.DropInfo.Valid = !(e.DropInfo.Index == -1 && column.FieldName == "ContactName");
    }
}
vb
Imports DevExpress.XtraGrid.Views.Base

Private Sub BandedGridView1_DragObjectOver(ByVal sender As Object, _
  ByVal e As DragObjectOverEventArgs) Handles BandedGridView1.DragObjectOver
    If TypeOf e.DragObject Is GridColumn Then
        Dim column As GridColumn = CType(e.DragObject, GridColumn)        
        e.DropInfo.Valid = Not (e.DropInfo.Index = -1 And column.FieldName = "ContactName")
    End If
End Sub

See Also

DragObjectDrop

DragObjectStart

GridView Class

GridView Members

DevExpress.XtraGrid.Views.Grid Namespace