Kbase P170096: How to enable Dragging and Dropping items between two UltraGrids in .NETUI
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  28/07/2010 |
|
Status: Unverified
SYMPTOM(s):
How to enable Dragging and Dropping items between two UltraGrids in .NETUI
How to Drag and Drop items between two UltraGrids
How to drag rows from one UltraGrid and move them to a second UltraGrid with the same schema
FACT(s) (Environment):
Windows
OpenEdge 10.2x
FIX:
- Subscribe both grids to the DragOver event and subscribe them both to the following generic method to handle the drag over effect:
METHOD PRIVATE VOID ultraGrid_DragOver( INPUT sender AS System.Object, INPUT e AS System.Windows.Forms.DragEventArgs ):
DEFINE VARIABLE oGrid AS UltraGrid NO-UNDO.
DEFINE VARIABLE oPointInGridCoords AS System.Drawing.Point NO-UNDO.
e:Effect = DragDropEffects:Move.
oGrid = CAST(sender,UltraGrid).
oPointInGridCoords = oGrid:PointToClient(NEW System.Drawing.Point(e:X,e:Y)).
IF oPointInGridCoords:Y LT 20 THEN /* Scroll up.*/
oGrid:ActiveRowScrollRegion:Scroll(RowScrollAction:LineUp).
ELSE IF oPointInGridCoords:Y GT oGrid:Height - 20 THEN /* Scroll down.*/
oGrid:ActiveRowScrollRegion:Scroll(RowScrollAction:LineDown).
RETURN.
END METHOD.
- Subscribe both grids to the SelectionDrag event and subscribe them both to the following generig method to handle moving the rows from one grid to the other:
METHOD PRIVATE VOID ultraGrid_SelectionDrag( INPUT sender AS System.Object, INPUT e AS System.ComponentModel.CancelEventArgs ):
CAST(sender,UltraGrid):DoDragDrop(sender:Selected:Rows, System.Windows.Forms.DragDropEffects:Move).
RETURN.
END METHOD.
- Subscribe both grids to the DragDrop event and add the following code for the event handlers:
METHOD PRIVATE VOID ultraGrid2_DragDrop( INPUT sender AS System.Object, INPUT e AS System.Windows.Forms.DragEventArgs ):
DEFINE VARIABLE oSelRows AS SelectedRowsCollection NO-UNDO.
DEFINE VARIABLE hSrcQuery AS HANDLE NO-UNDO.
DEFINE VARIABLE hTgtQuery AS HANDLE NO-UNDO.
/* Get the handle of the source query from the bindingSource that feeds the Source grid */
hSrcQuery = THIS-OBJECT:bindingSource2:Handle.
/* Get the handle of the target query from the bindingSource that feeds the current grid */
hTgtQuery = THIS-OBJECT:bindingSource1:Handle.
oSelRows = CAST(CAST(e:Data,
System.Windows.Forms.IDataObject):GetData(Progress.Util.TypeHelper:GetType('Infragistics.Win.UltraWinGrid.SelectedRowsCollection')),
Infragistics.Win.UltraWinGrid.SelectedRowsCollection).
MoveRows(INPUT hSrcQuery,
INPUT hTgtQuery,
INPUT oSelRows).
RETURN.
END METHOD.
METHOD PRIVATE VOID ultraGrid1_DragDrop( INPUT sender AS System.Object, INPUT e AS System.Windows.Forms.DragEventArgs ):
DEFINE VARIABLE oSelRows AS SelectedRowsCollection NO-UNDO.
DEFINE VARIABLE hSrcQuery AS HANDLE NO-UNDO.
DEFINE VARIABLE hTgtQuery AS HANDLE NO-UNDO.
/* Get the handle of the source query from the bindingSource that feeds the Source grid */
hSrcQuery = THIS-OBJECT:bindingSource2:Handle.
/* Get the handle of the target query from the bindingSource that feeds the current grid */
hTgtQuery = THIS-OBJECT:bindingSource1:Handle.
&.nbsp; oSelRows = CAST(CAST(e:Data,
System.Windows.Forms.IDataObject):GetData(Progress.Util.TypeHelper:GetType('Infragistics.Win.UltraWinGrid.SelectedRowsCollection')),
Infragistics.Win.UltraWinGrid.SelectedRowsCollection).
MoveRows(INPUT hSrcQuery,
INPUT hTgtQuery,
INPUT oSelRows).
RETURN.
END METHOD.
- Add the following method to handle the actual move of the data from one temp-table to the other and re-open the queries.
METHOD PRIVATE VOID MoveRows( INPUT phSrcQuery AS HANDLE,
INPUT phTgtQuery AS HANDLE,
INPUT poSelRows AS SelectedRowsCollection ):
DEFINE VARIABLE oRow AS UltraGridRow NO-UNDO.
DEFINE VARIABLE iLoop AS INTEGER NO-UNDO.
DEFINE VARIABLE hSrcBuffer AS HANDLE NO-UNDO.
DEFINE VARIABLE hTgtBuffer AS HANDLE NO-UNDO.
DEFINE VARIABLE iCustNum AS INTEGER NO-UNDO.
DEFINE VARIABLE cPredicate AS CHARACTER NO-UNDO.
hSrcBuffer = phSrcQuery:GET-BUFFER-HANDLE(1).
hTgtBuffer = phTgtQuery:GET-BUFFER-HANDLE(1).
/* Loop through the selected rows */
DO iLoop = 0 TO poSelRows:Count - 1 TRANSACTION:
oRow = poSelRows[iLoop].
iCustNum = oRow:Cells["CustNum"]:Value.
cPredicate = "WHERE " + hSrcBuffer:NAME + ".CustNum EQ " + STRING(iCustNum).
hSrcBuffer:FIND-FIRST(cPredicate,EXCLUSIVE-LOCK) NO-ERROR.
IF hSrcBuffer:AVAILABLE THEN DO:
hTgtBuffer:BUFFER-CREATE ().
hTgtBuffer:BUFFER-COPY (hSrcBuffer).
hSrcBuffer:BUFFER-DELETE ().
END.
END. /* Selected row loop Row */
phSrcQuery:QUERY-PREPARE ("FOR EACH " + hSrcBuffer:NAME).
phSrcQuery:QUERY-OPEN ().
phTgtQuery:QUERY-PREPARE ("FOR EACH " + hTgtBuffer:NAME).
phTgtQuery:QUERY-OPEN ().
RETURN.
END METHOD.
.