Source : ARRAY1 dans LISTBOX1
Destionation : ARRAY2 dans LISTBOX2
Dans l'exemple suivant, on copie des éléments du tableau 1 de listbox 1 vers le tableau 2 de listbox 2
en restant appuyé sur le bouton gauche de la souris depuis la source et en le relachant dans la destination.
* DragAndDrop.wfm - Exemple des commandes Drag and Dop.
* -----------------------------------------------------
*
LOCAL F
F = new DragAndDropForm()
F.open()
*
* ------------------------------------------------------------------------------
CLASS DragAndDropForm of FORM
* ------------------------------------------------------------------------------
with (this)
metric := 6 && Pixels
height := 270
left := 300
top := 60
width := 315
text := "Exemple Drag and Drop"
mdi := .F.
endwith
*
this.TEXT1 = new TEXT(this)
with (this.TEXT1)
height := 20
left := 15
top := 20
width := 120
text := "Source"
endwith
*
this.TEXT2 = new TEXT(this)
with (this.TEXT2)
height := 20
left := 180
top := 20
width := 120
text := "Destination"
endwith
*
this.ARRAY1 = new Array()
this.ARRAY1.add("Pomme")
this.ARRAY1.add("Poire")
this.ARRAY1.add("Banane")
this.ARRAY1.add("Raisin")
this.ARRAY1.add("Kiwi")
this.ARRAY1.add("Mangue")
this.ARRAY1.add("Mandarine")
this.ARRAY1.add("Orange")
this.ARRAY1.add("Cerise")
this.ARRAY1.add("Fraise")
this.ARRAY1.add("Mûre")
this.ARRAY1.add("Groseille")
this.ARRAY1.add("Pruneau")
this.ARRAY1.add("Abricot")
this.ARRAY1.add("Myrtille")
this.ARRAY1.add("Noix de coco")
*
this.LISTBOX1 = new LISTBOX(this)
with (this.LISTBOX1)
onLeftMouseDown := class::LISTBOX1_OnLeftMouseDown
height := 195
left := 15
top := 40
width := 120
id := 101
dataSource := "array form.ARRAY1"
dragEffect := 1 && Copie.
sorted := .T. && Trier les données.
endwith
*
this.ARRAY2 = new Array()
*
this.LISTBOX2 = new LISTBOX(this)
with (this.LISTBOX2)
onDrop := class::LISTBOX2_OnDrop
height := 195
left := 180
top := 40
width := 120
id := 101
allowDrop := .T.
dataSource := "array form.ARRAY2"
sorted := .T. && Trier les données.
endwith
*
* ------------------------------------------------------------------------------
FUNCTION LISTBOX1_OnLeftMouseDown(flags, col, row)
* ------------------------------------------------------------------------------
*
* "this" désigne form.LISTBOX1
*
this.drag(this.name, this.value, "")
*
RETURN null
*
* ------------------------------------------------------------------------------
FUNCTION LISTBOX2_OnDrop(nLeft, nTop, cType, cName)
* ------------------------------------------------------------------------------
*
* "this" désigne form.LISTBOX2
*
form.ARRAY2.add(cName)
this.dataSource := "array form.ARRAY2" && Rafraichir LISTBOX2
*
RETURN .F.
*
ENDCLASS