PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • Overview
  • Example of Drag and Drop between a List Box control and a button
  • Example of Drag and Drop between a TreeView control and a TreeView Table control
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
Overview
This help page presents two examples of programmed Drag and Drop performed in a WINDEV application:
Example of Drag and Drop between a List Box control and a button
The following code is used to delete the data found in a List Box control by Drag and Drop to a graphic button containing a recycle bin. Only the move (cut/paste) is allowed. The move cursor is displayed during the move (cut/paste) between the List Box control and the "Bin" button.
  1. Definition of the source: the List Box control
    //- - Initializing the list box
    LST_List..DndSource = dndProgram
  2. Defining the target: the BTN_Bin button. In the initialization code of button, the procedures for managing Drag and Drop are also called by DnDEvent.
    In this example:
    • the dndDragOver event is used to change the mouse cursor ("Rollover" procedure).
    • the dndDrop event is used to program the process for managing the drop. In our case, this process corresponds to the deletion of element from the List Box control ("OnDrop" procedure).
    //- - Initializing the BTN_Bin button
    BTN_Bin..DndTarget = dndProgram

    // Call the OnDrop procedure when the left mouse button
    // is released on the BTN_Bin button
    DnDEvent("OnDrop", BTN_Bin, dndDrop)

    // Call the OnRollover procedure when the mouse cursor
    // moves between the source list and the BTN_Bin button
    DnDEvent("OnRollover", BTN_Bin, dndDragOver)
  3. Defining the procedures:
    PROCEDURE DndDragOver()
    // Cursor indicating the move
    DnDCursor(dndMove)

    PROCÉDURE OnDrop()
    // Only the move is allowed (not the copy)
    DnDAccept(dndMove)
    // Delete the element from the source control
    ListDelete(_DND.SourceControl)
Example of Drag and Drop between a TreeView control and a TreeView Table control
The window contains:
  • a memory TreeView control (filled by programming).
  • a memory TreeView Table control.
The following example is used to move a Treeview control element (or a branch and its children) into a treeview Table control. The two methods of programmed Drag and Drop are presented.
Method 1: Full programmed mode
  1. Defining the source control: the TreeView control:
    // -- Initialization code of TREE_MENU control
    TreeAdd(TREE_MENU, "STARTERS")
    TreeAdd(TREE_MENU, "STARTERS" + TAB + "Salad")
    TreeAdd(TREE_MENU, "STARTERS" + TAB + "Cooked meat")
    TreeAdd(TREE_MENU, "STARTERS" + TAB + "Prawn cocktail")
    TreeAdd(TREE_MENU, "MAIN COURSES")
    TreeAdd(TREE_MENU, "MAIN COURSES" + TAB + "Chicken stew")
    TreeAdd(TREE_MENU, "MAIN COURSES" + TAB + "Fish and chips")
    TreeAdd(TREE_MENU, "MAIN COURSES" + TAB + "Pasta with salmon")
    TreeAdd(TREE_MENU, "MAIN COURSES" + TAB + "Pasta alla carbonara")
    TreeAdd(TREE_MENU, "MAIN COURSES" + TAB + "Pork ribs")
    TreeAdd(TREE_MENU, "DESSERTS")
    TreeAdd(TREE_MENU, "DESSERTS" + TAB + "Caramel custard")
    TreeAdd(TREE_MENU, "DESSERTS" + TAB + "Chocolate cream")
    TreeAdd(TREE_MENU, "DESSERTS" + TAB + "Tiramisu")
    TreeAdd(TREE_MENU, "DESSERTS" + TAB + "Ice cream")
    TreeAdd(TREE_MENU, "DESSERTS" + TAB + "Apple pie")

    // Enable the programmed Drag and Drop
    TREE_MENU..DndSource = dndProgram
  2. Defining the target: the TreeView Table control. In the initialization code of TreeView Table control, the procedures for managing Drag and Drop are also called by DnDEvent.
    In this example:
    • the dndDragOver event is used to change the mouse cursor ("pRollover" procedure).
    • the dndDrop event is used to program the process for managing the drop. In our case, this process corresponds to the copy of the elements found in the Table control into the TreeView Table control ("pDrop" procedure).
      // -- Initializing the TreeView Table control
      TVT_MENU..DndTarget = dndProgram

      DnDEvent(pRollover, TVT_MENU, dndDragOver)
      DnDEvent(pDrop, TVT_MENU, dndDrop)
  3. Defining the procedures:
    PROCÉDURE pRollover()

    // Cursor indicating the move
    DnDCursor(dndMove)

    PROCÉDURE pDrop()

    // Only the move is allowed (not the copy)
    DnDAccept(dndMove)

    sRoot is string
    sLeaf is string
    sElement is string
    sChild is string

    sElement = TreeSelect(TREE_MENU)
    sRoot = ExtractString(sElement, 1, TAB, FromBeginning)
    sLeaf = ExtractString(sElement, 1, TAB, FromEnd)

    IF sLeaf = sRoot THEN
    IF TableSeekChild(COL_TREE, sRoot) = -1 THEN
    TableAddChild(TVT_MENU, 0, sRoot)
    END

    sChild = TreeGiveChild(TREE_MENU, sRoot, tvFirst)
    WHILE sChild <> ""
    TableAddChild(TVT_MENU, sRoot, sChild)
    sChild = TreeGiveChild(TREE_MENU, sRoot, tvNext)
    END
    ELSE
    IF TableSeekChild(COL_TREE, sRoot) = -1 THEN
    TableAddChild(TVT_MENU, 0, sRoot)
    END
    TableAddChild(TVT_MENU, sRoot, sLeaf)
    END
Method 2: Simplified programed mode
  1. Defining the source control: the TreeView control.
    TreeAdd(TREE_MENU1, "STARTERS")
    TreeAdd(TREE_MENU1, "STARTERS" + TAB + "Salad")
    TreeAdd(TREE_MENU1, "STARTERS" + TAB + "Cooked meat")
    TreeAdd(TREE_MENU1, "STARTERS" + TAB + "Prawn cocktail")
    TreeAdd(TREE_MENU1, "MAIN COURSES")
    TreeAdd(TREE_MENU1, "MAIN COURSES" + TAB + "Chicken stew")
    TreeAdd(TREE_MENU1, "MAIN COURSES" + TAB + "Fish and chips")
    TreeAdd(TREE_MENU1, "MAIN COURSES" + TAB + "Pasta with salmon")
    TreeAdd(TREE_MENU1, "MAIN COURSES" + TAB + "Pasta alla carbonara")
    TreeAdd(TREE_MENU1, "MAIN COURSES" + TAB + "Pork ribs")
    TreeAdd(TREE_MENU1, "DESSERTS")
    TreeAdd(TREE_MENU1, "DESSERTS" + TAB + "Caramel custard")
    TreeAdd(TREE_MENU1, "DESSERTS" + TAB + "Chocolate cream")
    TreeAdd(TREE_MENU1, "DESSERTS" + TAB + "Tiramisu")
    TreeAdd(TREE_MENU1, "DESSERTS" + TAB + "Ice cream")
    TreeAdd(TREE_MENU1, "DESSERTS" + TAB + "Apple pie")
    // Enable the programmed Drag and Drop
    TREE_MENU1..DndSource = dndProgram
  2. Defining the target: TreeView table
    // -- Initializing the TreeView Table control
    TVT_MENU1..DndTarget = dndProgram
  3. Adding processes specific to Drag and Drop into the code of the target control (code of TreeView Table control).
    • Display the processes of the TreeView Table control ("Code" from the popup menu of the control).
    • Click the different icons representing the Drag and Drop processes that must be added:
    • In our example, the processes to add are:
      • Rollover in target Drag/Drop (dndDragOver).
      • Drop in target Drag/Drop (dndDrop).
  4. Enter the code corresponding to the actions to perform:
    • Process for Drop in target Drag/Drop (dndDrop)
      // Only the move is allowed (not the copy)
      DnDAccept(dndMove)

      sRoot is string
      sLeaf is string
      sElement is string
      sChild is string

      sElement = TreeSelect(TREE_MENU1)
      sRoot = ExtractString(sElement, 1, TAB, FromBeginning)
      sLeaf = ExtractString(sElement, 1, TAB, FromEnd)

      IF sLeaf = sRoot THEN
      IF TableSeekChild(COL_TREE1, sRoot) = -1 THEN
      TableAddChild(TVT_MENU1, 0, sRoot)
      END

      sChild = TreeGiveChild(TREE_MENU1, sRoot, tvFirst)
      WHILE sChild <> ""
      TableAddChild(TVT_MENU1, sRoot, sChild)
      sChild = TreeGiveChild(TREE_MENU1, sRoot, tvNext)
      END
      ELSE
      IF TableSeekChild(COL_TREE1, sRoot) = -1 THEN
      TableAddChild(TVT_MENU1, 0, sRoot)
      END
      TableAddChild(TVT_MENU1, sRoot, sLeaf)


      END
    • Process for Rollover in target Drag/Drop (dndDragOver)
      // Cursor indicating the move
      DnDCursor(dndMove)
Related Examples:
Drag and drop Unit examples (WINDEV): Drag and drop
[ + ] Using Drag & Drop with the WLanguage functions.
The following topics are presented in this example:
1/ How to manage Drag&Drop between WINDEV controls
2/ How to manage Drag&Drop from the Windows file explorer to a WINDEV control
Drag & Drop is used to move objects via the mouse. "Drag" consists in clicking an object and moving the mouse while keeping the left button down. "Drop" consists in releasing the left mouse button.
Drag & Drop can be used with WINDEV on the List Box, TreeView, Table and Image controls.
Minimum required version
  • Version 17
Comments
Click [Add] to post a comment