I have an application that needs to support dragging rows within a GDBG and onto another control. Row dragging within the grid was no problem, but I''m having difficulty with getting them to another control.
The internal row drag handler doesn''t seem to know when it leaves the grid or form. It just tracks mouse position relative to the row headers.
Do I need to implement a replacement row drag handler to implement dragging within and off the grid? If so, are there hooks so I still have the insert bar displayed as the cursor is dragged within the grid?
ADAdministrator Syncfusion Team August 19, 2004 08:59 AM
There are two type of drag operations in the grid with respect to rows.
One is moving a row to a new location in the grid. This row moving is controlled by the AllowDragSelectedRows property and is off by default in a GridDataBoundGrid. Using this functionality will only drag rows within the same grid to move them within the grid, and is only really supported in a GridControl that holds its own data. In a GridControl, you would select a row or several rows by dragging the row headers, and then mousedown on one of the selected headers to drag the rows to a new position. You can turn on the UI behavior in a GridDataBoundGrid, but it will not actually move the rows for you.
The second drag functionality is OLE D&D. This is supported in a GridDataBoundGrid and a GridControl. If you select several rows, and then place the cursor at the border of the selection, you should get a drag cursor that starts a OLE D&D. If you have set grid.AllowDrop = false, you should get the nodrop cursor while you are over the grid. Then if you move over other controls that have AllowDrop = true set, and accept a Text drop, you should be able to drop the rows. The data will be tab delimited text for columns and newline delimited rows. If you want to use a custom data object as part of the drop data, you can do so using the grid1.Model.QueryOleDataSourceData event to put your own custom object into the data object being used by the OLE D&D.
So, if you can use the default OLE D&D support, that would be the simplest way to enable dragging rows to another control.
DLDoug LindAugust 19, 2004 10:46 AM
Thanks for the quick response Clay.
I tried using the 2nd (default) method but do not get the drag icon when hovering over the selected rows.
I have enabled the grid set as an OLE source and have .AllowDrop = True
Is there something else I need to set to get the row drag cursor to show or should I be handling it all in code?
ADAdministrator Syncfusion Team August 19, 2004 10:56 AM
No, you should only have to drag a GridDataBoundGrid onto a form, and populate it with a datasource. The OLE D&D is turned on by default. If you then select several rows, and then move the cursor to the bottom of the selection, you should see a drop cursor appear. When this cursor is present, you should be able to mousedown and drag the rows to, say Excel.
In this forum thread, http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=17811, there is a little sample at the bottom, that is more or less a default grid. That sample works for me as I described above. Does it work for you?
DLDoug LindAugust 19, 2004 11:15 AM
OK I see that it does work. I was expecting behavior like with column drags, where the cursor changes whereever you are in the column header.
Thanks for the support ;-)
DLDoug LindAugust 24, 2004 06:17 AM
One more question...
In your previous replies you mentioned using grid1.Model.QueryOleDataSourceData event to create custom data. When I try to create a handler for the event in a GridDataBoundGrid, the event is not available. Can you post a snippet showing how the handler is declared for a GDBG? Below is what I was trying:
Private Sub gdbgOrders_QueryOleDataSourcedata(ByVal sender As Object, ByVal e As GridQueryOleDataSourceDataEventArgs) Handles gdbgOrders.QueryOleDataSourceData
ADAdministrator Syncfusion Team August 24, 2004 06:26 AM
It is a member of the grid.Model object and not the grid. So, to subscribe to the event, try code like:
AddHandler gdbgOrders.Model.QueryOleDataSourcedata, addressof gdbgOrders_QueryOleDataSourcedata
DLDoug LindAugust 24, 2004 06:37 AM
DLDoug LindAugust 24, 2004 07:37 AM
I''m having an issue with the GDBG wanting to move the rows itself and messing up the row layout. I want to handle the actual move myself in the DataSource. Is there a way to disable the internal row moving? I tried disabling the DragDropDropTargetFlags but that just made the drag box go away, and the rows were still moved.