Home Forums WinForms controls Xceed Grid for WinForms How to drag and drop rows to and from a grid

Viewing 1 post (of 1 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #17815 |

    The grid does not provide built-in functionality to copy and paste or drag and drop rows to and from another application such as Excel, however it is quite easy for you to implement (a sample is provided below). In order to drag rows from a grid you need to:

    1. Handle each cell’s MouseDown, MouseUp and MouseMove events.
    2. In the MouseMove event, once you have determined that the mouse has moved while the mouse button was pressed, you need to create a DataObject that will contain a compatible DataFormat. For example plain text, CSV or HTML data formats are all supported by Excel.
    3. Once you have your DataObject, call the grid’s DoDragDrop method.

    You can then drag your rows into Excel or any other application that supports the data formats you provided. In order to drop rows onto a grid you need to:

    1. Handle each cell’s DragOver and DragDrop events.
    2. You must set the AllowDrop property of each cell as well as the AllowDrop property of the grid to true.
    3. Retrieve the DataObject being dropped using the DataObject’s GetData method. You can decide which data format you want to use. The easiest one to use with the grid is plain text (DataFormats.PlainText).
    4. Once you have your DataObject, you will need to parse it and retrieve the data.
    5. Once you have retrieved your data, add the new rows to the grid.

    Imported from legacy forums. Posted by Xceed admin (had 1206 views)

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.