Ticket T1037829
Visible to All Users

GridControl Drag and Drop Behaviour - Get the Rowhandle of the row on which the Drag started

created 3 years ago

Thanks to previous advice, I'm nearly there - How can I get the Rowhandle of the row which started the drag drop. I need it to deal with the data I'm handling, and to ensure that the Drop is always on the same row.

Can I get this within the behaviour routines, or do I need to store using a MouseDown?

Thanks.

Comments (2)
DevExpress Support Team 3 years ago

    Hello Bob,

    From what I gather, you need to obtain the row handles of a source grid in the DragDropBehavior.DragDrop event. If so, use the DragDropEventArgs.Data property or the DragDropEventArgs.GetData method to obtain source row handles. This approach is illustrated in the following example - How to reorder grid rows by drag and drop:

    C#
    int[] sourceHandles = e.GetData<int[]>(); int targetRowHandle = hitInfo.RowHandle; int targetRowIndex = targetGrid.GetDataSourceRowIndex(targetRowHandle); List<DataRow> draggedRows = new List<DataRow>(); foreach (int sourceHandle in sourceHandles) { int oldRowIndex = sourceGrid.GetDataSourceRowIndex(sourceHandle); DataRow oldRow = sourceTable.Rows[oldRowIndex]; draggedRows.Add(oldRow); }

    If your task is different, please describe it in detail, and also send us a simple example illustrating your implementation and requirements. This will help us narrow down the issue and find its cause quickly.

    I look forward to your results.

      Thanks for reply. I looked at this, but I need the source rowhandle during the drag operation (so that I can show that the drop cannot take place if the mouse moves away from the source row to another. (We are doing stuff that relates to a single row, so the dragdrop will always be from one column to another within the same row).

      Thanks.

      Answers approved by DevExpress Support

      created 3 years ago

      Hi Bob,

      Thank you for the clarification. As mentioned by Igor, you can use the Data property or the GetData method included in the event's arguments to get the source row handles. The above property and method are also available during the DragOver event if you want to set conditions while dragging an object. I suggest playing with the example shared by Igor to see how the properties and elements used interact with each other.

      Below is a sample code that demonstrates the main idea of the approach:

      C#
      private void dragDropEvents1_DragOver(object sender, DevExpress.Utils.DragDrop.DragOverEventArgs e) { var args = DragOverGridEventArgs.GetDragOverGridEventArgs(e); int[] sourceHandles = e.GetData<int[]>(); int targetRowHandle = args.HitInfo.RowHandle; if (args.HitInfo.InRowCell) { if (sourceHandles[0] != targetRowHandle) { e.Cursor = Cursors.No; } else { e.Cursor = Cursors.Hand; } } args.Handled = true; }

      I recommend reading through the documentation of the events used in the drag-and-drop operation such as DragOver and DropDrop to learn more about the available properties. Since you might require getting the UI element under the mouse pointer, I also recommend reading how hit information works which can help you if you want to target specific UI elements in the grid. As you can see in the above sample, I have used the args.HitInfo.InRowCell condition to check if the mouse pointer is within a cell and args.HitInfo.RowHandle to get the row handle under the mouse pointer. I hope you find this information useful.

      See also:
      Drag-and-Drop Grid Rows
      DevExpress WinForms Cheat Sheet - Drag-and-Drop Within/Between Controls
      DevExpress WinForms Cheat Sheets - Get information about the UI elements located at the specified point

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.