public form1 form1=newobject("form1") form1.caption = "list box example" form1.list1.additem("Item1") form1.list1.additem("Item2") form1.list2.additem("Box 2 Item1") form1.list2.additem("Box 2 Item2") form1.list1.additem("Item3") form1.list1.additem("Item4") form1.list1.additem("Item5") form1.list1.additem("Item6") form1.list1.additem("Item7") form1.list1.additem("Item8") form1.show return define class form1 as form add object list1 as zlistbox with ; height = 170, ; left = 24, ; top = 24, ; width = 100, ; name = "List1" add object list2 as zlistbox with ; height = 170, ; left = 124, ; top = 24, ; width = 100, ; name = "List2" enddefine Define Class zlistbox As ListBox OLEDragMode = 1 OLEDropMode = 1 OLEDropEffects = 1 FontName = "Arial" FontSize = 9 Height = 200 MoverBars = .T. MultiSelect = .T. Width = 200 AutoHideScrollbar = 1 *-- What user defined data type is accepted by this object. oledatatype = "zListBox" objectid = "abc123" Name = "zlistbox" *-- Removes all selected items in the list. Procedure removeselected * Deletes all list items that are selected. * Returns the number of items deleted. Local xx, deletecnt With This deletecnt = 0 For xx = .ListCount To 1 Step -1 If .Selected(m.xx) deletecnt = m.deletecnt + 1 .RemoveItem(m.xx) Endif Endfor Return m.deletecnt Endwith Endproc *-- Appends an array to the list. Procedure Import Lparameters SourceA, startrow External Array SourceA Local maxcol, xx, yy, nextrow, rowcount With This rowcount = 0 nextrow = Iif(Pcount()=2, m.startrow, .ListIndex) If Type("sourceA", 1)="A" .ColumnCount = Max(Alen(SourceA, 2), .ColumnCount) rowcount = Alen(SourceA, 1) For xx = 1 To m.rowcount nextrow = m.nextrow + 1 .AddItem(Transform(SourceA[m.xx, 1]), m.nextrow, 1) For yy = 2 To Alen(SourceA, 2) .List[m.nextrow, m.yy] = Transform(SourceA[m.xx, m.yy]) Endfor Endfor Endif Return m.rowcount Endwith Endproc *-- Exports the data to an array or cursor. Procedure Export * destination: cursor or array * exporttype: bit 0: 0=All Items, 1=Selected Items * Returns: Number of rows exported Lparameters destination, exporttype Local xx, yy, maxcol, itemcnt External Array destination itemcnt = 0 exporttype = Iif(Vartype(m.exporttype)="N", m.exporttype, 0) With This Do Case Case .ListCount = 0 Return 0 Case Type("destination", 1)="A" maxcol = Max(.ColumnCount, 1) For xx = 1 To .ListCount If .Selected(m.xx) Or m.exporttype=0 itemcnt = m.itemcnt + 1 Dimension destination[m.itemcnt, m.maxcol] For yy = 1 To m.maxcol destination[m.itemcnt, m.yy] = .List[m.xx, m.yy] Endfor Endif Endfor Return m.itemcnt Otherwise Error 11, "Invalid DESTINATION parameter in zlistbox.export" Endcase Endwith Endproc *-- Sets the listindex using the mouse location's Y coordinate on thisform. Procedure coord2index * Converts the Y coordinate of the mouse position to the corresponding listindex. * If you pass tophalfL=.t. and the mouse position is located in the upper half * of a displayed list item, the prior item's listindex is returned. Lparameters ycoordN, tophalfL Local fontheight, linegap, lineheight, newidx With This fontheight = Fontmetric(1, .FontName, .FontSize, Iif(.FontBold, "B", "") + Iif(.FontItalic, "I", "")) linegap = Fontmetric(5, .FontName, .FontSize, Iif(.FontBold, "B", "") + Iif(.FontItalic, "I", "")) + 2 lineheight = (m.fontheight + m.linegap) Do Case Case Pcount()=0 newidx = (.Height - 4) / m.lineheight + .TopIndex - 1 Case m.tophalfL newidx = Min(Round(Max(m.ycoordN - .Top - 2, 0) / m.lineheight, 0), .ListCount) + .TopIndex - 1 Otherwise newidx = Min(Ceiling(Max(m.ycoordN - .Top - 2, 0) / m.lineheight), .ListCount) + .TopIndex - 1 Endcase Return m.newidx Endwith Endproc Procedure OLEDragDrop * Get's the source data and source id and imports it. Assumes * this is a move operation. Lparameters DataO, nEffect, nButton, nShift, nXCoord, nYCoord Local textA[1], sourceid, newidx With DataO Nodefault && Required when changing nEffect nEffect = 0 If .GetFormat("OLE Variant Array") And (.GetFormat(This.oledatatype) Or .GetFormat(This.objectid)) .GetData("OLE Variant Array", @textA) nEffect = 2 && 1=Copy, 2=Move, 4=Link newidx = This.coord2index(m.nYCoord, .T.) This.Import(@textA, m.newidx) Endif Return Endwith Endproc Procedure OLEDragOver Lparameters oDataObject, nEffect, nButton, nShift, nXCoord, nYCoord, nState This.OLEDropHasData = 1 Endproc Procedure OLECompleteDrag * This is the final event of the drag/drop activities. * Upon completion of the DragDrag operation, delete the source rows Lparameters nEffect With This If m.nEffect = 2 .removeselected() Endif Endwith Endproc Procedure OLEStartDrag Lparameters oDataObject, nEffect Local textA[1] With This oDataObject.ClearData If This.Export(@textA, 1)>0 && Export Selected Data Only oDataObject.SetFormat("OLE Variant Array") oDataObject.SetFormat(.oledatatype) oDataObject.SetData(@textA, "OLE Variant Array") .objectid = Sys(2015) && Set a random object ID to allow self movement of list items oDataObject.SetFormat(.objectid) Endif Endwith Endproc Enddefine