Back to Devexpress

DragDropGridEventArgs.GetDragDropGridEventArgs(DragDropEventArgs) Method

windowsforms-devexpress-dot-xtragrid-dot-views-dot-grid-dot-dragdropgrideventargs-dot-getdragdropgrideventargs-x28-devexpress-dot-utils-dot-dragdrop-dot-dragdropeventargs-x29.md

latest4.5 KB
Original Source

DragDropGridEventArgs.GetDragDropGridEventArgs(DragDropEventArgs) Method

Calculates grid-specific event arguments.

Namespace : DevExpress.XtraGrid.Views.Grid

Assembly : DevExpress.XtraGrid.v25.2.dll

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

Declaration

csharp
public static DragDropGridEventArgs GetDragDropGridEventArgs(
    DragDropEventArgs e
)
vb
Public Shared Function GetDragDropGridEventArgs(
    e As DragDropEventArgs
) As DragDropGridEventArgs

Parameters

NameTypeDescription
eDragDropEventArgs

An object that contains event arguments.

|

Returns

TypeDescription
DragDropGridEventArgs

An object that contains grid-specific event arguments.

|

Example

The example below shows how to copy data from a tree list to a grid.

csharp
using DevExpress.Utils.DragDrop;

//The code below assumes that you are moving data from a tree list to a grid.
//Create new grid rows, and populate them with data from tree list nodes.
private void dragDropEvents1_DragDrop(object sender, DragDropEventArgs e) {
    List<TreeListNode> list = e.Data as List<TreeListNode>;
    foreach (TreeListNode node in list) {
        gridView1.AddNewRow();
        gridView1.SetRowCellValue(GridControl.NewItemRowHandle, gridView1.Columns["DEPARTMENT"], node.GetValue(colDEPARTMENT1));
    }
    e.Handled = true;
}
vb
Imports DevExpress.Utils.DragDrop

'The code below assumes that you are moving data from a tree list to a grid.
'Create new grid rows, and populate them with data from tree list nodes.
Private Sub dragDropEvents1_DragDrop(ByVal sender As Object, ByVal e As DevExpress.Utils.DragDrop.DragDropEventArgs) _
    Handles dragDropEvents1.DragDrop
    Dim list As List(Of TreeListNode) = TryCast(e.Data, List(Of TreeListNode))
    For Each node As TreeListNode In list
        gridView1.AddNewRow()
        gridView1.SetRowCellValue(GridControl.NewItemRowHandle, gridView1.Columns("DEPARTMENT"), node.GetValue(colDEPARTMENT1))
    Next node
    e.Handled = True
End Sub

Note

When you handle the DragDrop event for a grid view, use the static (Shared in VB) DragDropGridEventArgs.GetDragDropGridEventArgs method to calculate arguments specific to the grid view.

csharp
using DevExpress.Utils.DragDrop;
using DevExpress.XtraGrid.Views.Grid;

dragDropEvents1.DragDrop += Behavior_DragDrop;

private void Behavior_DragDrop(object sender, DragDropEventArgs e) {
   DragDropGridEventArgs args = DragDropGridEventArgs.GetDragDropGridEventArgs(e);
   //You can also cast DragDropEventArgs to DragDropGridEventArgs.
   //DragDropGridEventArgs args = (DragDropGridEventArgs)e;
}
vb
Imports DevExpress.Utils.DragDrop
Imports DevExpress.XtraGrid.Views.Grid

AddHandler DragDropEvents1.DragDrop, AddressOf Behavior_DragDrop
Private Sub Behavior_DragDrop(ByVal sender As Object, ByVal e As DragDropEventArgs)
   Dim args As DragDropGridEventArgs = DragDropGridEventArgs.GetDragDropGridEventArgs(e)
   'You can also cast DragDropEventArgs to DragDropGridEventArgs.
   'Dim args As DragDropGridEventArgs = CType(e, DragDropGridEventArgs)
End Sub

Note

Run the XtraTreeList or XtraGrid demo and click Open Solution for more examples.

See Also

DragDropGridEventArgs Class

DragDropGridEventArgs Members

DevExpress.XtraGrid.Views.Grid Namespace