AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Este contenido se ha traducido automáticamente.  Haga clic aquí  para ver la versión en inglés.
Ayuda / WLanguage / Funciones WLanguage / Controles, páginas y ventanas / Funciones de arrastrar y soltar
  • Overview
  • Example of Drag and Drop between a List Box and Button control
  • Example of Drag and Drop between a TreeView control and a TreeView Table control
WINDEV
WindowsLinuxJavaReportes y ConsultasCódigo de Usuario (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Código Navegador
WINDEV Mobile
AndroidWidget Android iPhone/iPadIOS WidgetApple WatchMac Catalyst
Otros
Procedimientos almacenados
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 and Button control
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. Source definition: the List Box control
    //- - Initialisation du champ Liste
    LISTE_Liste.DndSource = dndProgram
  2. Target definition: the BTN_Poubelle button. In the button initialization code, the Drag and Drop management procedures are also called using 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).
    //- - Initialisation bouton BTN_Poubelle
    BTN_Poubelle.DndCible = dndProgram
    
    // Appel de la procédure SurLâcher lorsque le bouton gauche 
    // de la souris est relâché sur le bouton BTN_Poubelle
    DnDEvent("SurLâcher", BTN_Poubelle, dndDrop)
    
    // Appel de la procédure SurSurvol lorsque le curseur de la souris 
    // se déplace entre la liste source et le bouton BTN_Poubelle
    DnDEvent("SurSurvol", BTN_Poubelle, dndDragOver)
  3. Defining the procedures:
    PROCEDURE SurSurvol()
    // Curseur indiquant le déplacement
    DnDCursor(dndMove)

    PROCEDURE SurLâcher()
    // Seul le déplacement est autorisé (pas le copier)
    DnDAccept(dndMove)
    // Suppression de l'élément dans le champ source
    ListDelete(_DND.SourceControl)
Example of Drag and Drop between a TreeView control and a TreeView Table control
The window contains:
  • a TreeView control populated programmatically.
  • a TreeView Table control populated programmatically.
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 program mode
  1. Definition of the source field: the TreeView control:
    // -- Code Initialisation champ ARBRE_MENU 
    TreeAdd(ARBRE_MENU, "ENTREES")
    TreeAdd(ARBRE_MENU, "ENTREES" + TAB + "Crudités")
    TreeAdd(ARBRE_MENU, "ENTREES" + TAB + "Charcuterie")
    TreeAdd(ARBRE_MENU, "ENTREES" + TAB + "Avocats")
    TreeAdd(ARBRE_MENU, "PLATS")
    TreeAdd(ARBRE_MENU, "PLATS" + TAB + "Poulet curry")
    TreeAdd(ARBRE_MENU, "PLATS" + TAB + "Sole meunière")
    TreeAdd(ARBRE_MENU, "PLATS" + TAB + "Tagliatelle au saumon")
    TreeAdd(ARBRE_MENU, "PLATS" + TAB + "Tagliatelle carbonara")
    TreeAdd(ARBRE_MENU, "PLATS" + TAB + "Entrecôte")
    TreeAdd(ARBRE_MENU, "DESSERTS")
    TreeAdd(ARBRE_MENU, "DESSERTS" + TAB + "Crème brûlée")
    TreeAdd(ARBRE_MENU, "DESSERTS" + TAB + "Mousse chocolat")
    TreeAdd(ARBRE_MENU, "DESSERTS" + TAB + "Tiramisu")
    TreeAdd(ARBRE_MENU, "DESSERTS" + TAB + "Glace")
    TreeAdd(ARBRE_MENU, "DESSERTS" + TAB + "Tarte pomme")
    
    // Activation du Drag and Drop programmé
    ARBRE_MENU.DndSource = dndProgram
  2. Defining the target: the TreeView Table control field. 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).
      // -- Initialisation du champ Table hiérarchique 
      TABLEH_MENU.DndCible = dndProgram
      
      DnDEvent(pSurvol, TABLEH_MENU, dndDragOver)
      DnDEvent(pLacher, TABLEH_MENU, dndDrop)
  3. Defining the procedures:
    PROCEDURE pSurvol()
    
    // Curseur indiquant le déplacement
    DnDCursor(dndMove)

    PROCEDURE pLacher()
    
    // Seul le déplacement est autorisé (pas le copier)
    DnDAccept(dndMove)
    
    sRacine is string
    sFeuille is string
    sElement is string
    sFils is string
    
    sElement = TreeSelect(ARBRE_MENU)
    sRacine = ExtractString(sElement, 1, TAB, FromBeginning)
    sFeuille = ExtractString(sElement, 1, TAB, FromEnd)
    
    IF sFeuille = sRacine THEN
    	IF TableSearchChild(COL_ARBRE, sRacine) = -1 THEN 
    		TableAddChild(TABLEH_MENU, 0, sRacine)
    	END
    
    	sFils = TreeGiveChild(ARBRE_MENU, sRacine, tvFirst)
    	WHILE sFils <> ""
    		TableAddChild(TABLEH_MENU, sRacine, sFils)
    		sFils = TreeGiveChild(ARBRE_MENU, sRacine, tvNext)
    	END
    ELSE
    	IF TableSearchChild(COL_ARBRE, sRacine) = -1 THEN
    		TableAddChild(TABLEH_MENU, 0, sRacine)
    	END
    	TableAddChild(TABLEH_MENU, sRacine, sFeuille)
    END
Method 2: Simplified program mode
  1. Definition of the source field: the TreeView control field.
    TreeAdd(ARBRE_MENU1, "ENTREES")
    TreeAdd(ARBRE_MENU1, "ENTREES" + TAB + "Crudités")
    TreeAdd(ARBRE_MENU1, "ENTREES" + TAB + "Charcuterie")
    TreeAdd(ARBRE_MENU1, "ENTREES" + TAB + "Avocats")
    TreeAdd(ARBRE_MENU1, "PLATS")
    TreeAdd(ARBRE_MENU1, "PLATS" + TAB + "Poulet curry")
    TreeAdd(ARBRE_MENU1, "PLATS" + TAB + "Sole meunière")
    TreeAdd(ARBRE_MENU1, "PLATS" + TAB + "Tagliatelle au saumon")
    TreeAdd(ARBRE_MENU1, "PLATS" + TAB + "Tagliatelle carbonara")
    TreeAdd(ARBRE_MENU1, "PLATS" + TAB + "Entrecôte")
    TreeAdd(ARBRE_MENU1, "DESSERTS")
    TreeAdd(ARBRE_MENU1, "DESSERTS" + TAB + "Crème brûlée")
    TreeAdd(ARBRE_MENU1, "DESSERTS" + TAB + "Mousse chocolat")
    TreeAdd(ARBRE_MENU1, "DESSERTS" + TAB + "Tiramisu")
    TreeAdd(ARBRE_MENU1, "DESSERTS" + TAB + "Glace")
    TreeAdd(ARBRE_MENU1, "DESSERTS" + TAB + "Tarte pomme")
    // Activation du Drag and Drop programmé
    ARBRE_MENU1..DndSource = dndProgram
  2. Target definition: Hierarchical table
    // -- Initialisation du champ Table hiérarchique
    TABLEH_MENU1.DndCible = dndProgram
  3. Adding EVENTS specific to Drag and Drop into the code of the target control (code of TreeView Table control).
    • Open the events of the TreeView Table control (select "Code" in the control context menu).
    • Display the optional events window: click on the "Add other events" link at the end of the field events.
    • In our example, the events 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:
    • Event for Drop in target Drag/Drop (dndDrop)
      // Seul le déplacement est autorisé (pas le copier)
      DnDAccept(dndMove)
      
      sRacine is string
      sFeuille is string
      sElement is string
      sFils is string
      
      sElement = TreeSelect(ARBRE_MENU1)
      sRacine = ExtractString(sElement, 1, TAB, FromBeginning)
      sFeuille = ExtractString(sElement, 1, TAB, FromEnd)
      
      IF sFeuille = sRacine THEN
      	IF TableSearchChild(COL_ARBRE1, sRacine) = -1 THEN
      		TableAddChild(TABLEH_MENU1, 0, sRacine)
      	END
      
      	sFils = TreeGiveChild(ARBRE_MENU1, sRacine, tvFirst)
      	WHILE sFils <> ""
      		TableAddChild(TABLEH_MENU1, sRacine, sFils)
      		sFils = TreeGiveChild(ARBRE_MENU1, sRacine, tvNext)
      	END
      ELSE
      	IF TableSearchChild(COL_ARBRE1, sRacine) = -1 THEN
      		TableAddChild(TABLEH_MENU1, 0, sRacine)
      	END
      	TableAddChild(TABLEH_MENU1, sRacine, sFeuille)
      END
    • Event for Rollover in target Drag/Drop (dndDragOver)
      // Curseur indiquant le déplacement 
      DnDCursor(dndMove)
Versión mínima requerida
  • Versión 17
Comentarios
Haga clic en [Agregar] para publicar un comentario

Última modificación: 21/09/2024

Señalar un error o enviar una sugerencia | Ayuda local