【求助】如何顺序打印改变后的列表框内容?
假设列表框内容的初始排列顺序是a,b,c,d,e,现在我用列表框左侧的移动滑块把顺序排列成了c,b,a,d,e,那么如何按新的顺序,依次打印c,b,a,d,e?哈哈,不知道说清楚了没有?
CLEAR ALL
CLOSE DATABASES ALL
CLEAR
goForm = CREATEOBJECT("C_Form")
goForm.Show
READ EVENTS
CLOSE DATABASES ALL
CLEAR ALL
RETURN
DEFINE CLASS C_Form AS Form
Caption = "测试例程"
MinWidth = 800
MinHeight = 600
AutoCenter = .T.
KeyPreview = .T.
ADD OBJECT List1 AS my_ListBox
ADD OBJECT Label1 AS Label WITH Caption = ""
PROCEDURE Arrange
WITH ThisForm.List1
.Top = 5
.Left = 5
.Height = ThisForm.Height - .Top - 5
.Width = ThisForm.Width / 2 - .Left - 5
ENDWITH
WITH ThisForm.Label1
.Top = 5
.Left = ThisForm.Width / 2 + 5
.Height = ThisForm.Height - .Top - 5
.Width = ThisForm.Width - .Left - 5
ENDWITH
ENDPROC
PROCEDURE Activate
ThisForm.Arrange
ENDPROC
PROCEDURE Resize
ThisForm.Arrange
ENDPROC
#DEFINE K_ESC 27
PROCEDURE KeyPress(tnKeyCode, tnShiftAltCtrl)
IF tnKeyCode == K_ESC
RELEASE ThisForm
ENDIF
ENDPROC
#UNDEFINE K_ESC
PROCEDURE Destroy
CLEAR EVENTS
ENDPROC
PROCEDURE List1.Init
DODEFAULT()
WITH This
.MoverBars = .T.
DIMENSION .ItemArray[7]
.ItemArray[1] = "AAA"
.ItemArray[2] = "BBB"
.ItemArray[3] = "CCC"
.ItemArray[4] = "DDD"
.ItemArray[5] = "EEE"
.ItemArray[6] = "FFF"
.ItemArray[7] = "GGG"
.SetItems
ENDWITH
ENDPROC
PROCEDURE List1.OnMoveItem(tnSource, tnShift, tnCurrentIndex, tnMoveBy)
DODEFAULT(tnSource, tnShift, tnCurrentIndex, tnMoveBy)
ThisForm.Label1.Refresh
ENDPROC
#DEFINE CR_LF CHR(13)+CHR(10)
PROCEDURE Label1.Refresh
LOCAL lnIndex, lcText
lcText = ""
WITH ThisForm.List1
IF .MoverBars
FOR lnIndex = 1 TO .ListCount
lcText = lcText + .ItemArray[lnIndex]
IF lnIndex < .ListCount
lcText = lcText + CR_LF
ENDIF
NEXT
ENDIF
ENDWITH
This.Caption = lcText
ENDPROC
#UNDEFINE CR_LF
ENDDEFINE
DEFINE CLASS my_ListBox AS ListBox
PROCEDURE Init
WITH This
IF .MoverBars .AND. (.RowSourceType <= 1) .AND. (VARTYPE(.ItemArray) == "U")
.AddProperty("ItemArray[1]")
.ItemArray[1] = Null
ENDIF
ENDWITH
ENDPROC
PROCEDURE MoverBars_Assign(tlOn)
WITH This
IF .RowSourceType <= 1
.MoverBars = tlOn
IF .MoverBars
.AddProperty("ItemArray[1]")
.ItemArray[1] = Null
ENDIF
ELSE
MESSAGEBOX("ListBox类型控件" + .Name + "使用MoverBars属性必须设置.RowSourceType = 0 或 1", 64, This.Class)
.MoverBars = .F.
ENDIF
ENDWITH
ENDPROC
PROCEDURE SetItems
LOCAL lnIndex
WITH This
IF .MoverBars .AND. (.RowSourceType <= 1) .AND. (VARTYPE(.ItemArray) != "U")
.Clear
FOR lnIndex = 1 TO ALEN(.ItemArray,1)
IF !ISNULL(.ItemArray[lnIndex])
.AddItem(.ItemArray[lnIndex])
ELSE
ADEL(.ItemArray, lnIndex)
ENDIF
NEXT
ENDIF
ENDWITH
ENDPROC
PROCEDURE OnMoveItem(tnSource, tnShift, tnCurrentIndex, tnMoveBy)
LOCAL lcItem
WITH This
IF .MoverBars .AND. (.RowSourceType <= 1) .AND. (VARTYPE(.ItemArray) != "U")
lcItem = .ItemArray[tnCurrentIndex]
.ItemArray[tnCurrentIndex] = .ItemArray[tnCurrentIndex + tnMoveBy]
.ItemArray[tnCurrentIndex + tnMoveBy] = lcItem
ENDIF
ENDWITH
ENDPROC
ENDDEFINE
[ 本帖最后由 TonyDeng 于 2011-10-5 21:39 编辑 ]