andyhu 发表于 2011-10-1 04:04:44

怎样通过上下按钮来排序listview/listbox的顺序?

如图,这种功能是怎样做出来的?
谢谢!

netegg 发表于 2011-10-1 04:10:56


;===============================================================================
; Function Name:    _GUICtrlListView_MoveItemsSelected()
; Description:      Moves Up or Down selected item(s) in ListView.
;
; Parameter(s):   $hListView          - ControlID or Handle of ListView control.
;                   $iDirection         - Define in what direction item(s) will move:
;                                           -1 - Move Up.
;                                          1 - Move Down.
;
; Requirement(s):   AutoIt 3.3.0.0
;
; Return Value(s):On seccess - Move selected item(s) Up/Down and return 1.
;                   On failure - Return "" (empty string) and set @error as following:
;                                                                  1 - No selected item(s).
;                                                                  2 - $iDirection is wrong value (not 1 and not -1).
;                                                                  3 - Item(s) can not be moved, reached last/first item.
;
; Note(s):          * If you select like 15-20 (or more) items, moving them can take a while :( (second or two).
;
; Author(s):      G.Sandler a.k.a CreatoR
;===============================================================================
Func _GUICtrlListView_MoveItemsSelected($hListView, $iDirection)
    Local $aSelected_Indices = _GUICtrlListView_GetSelectedIndices($hListView, 1)
   
    If UBound($aSelected_Indices) < 2 Then Return SetError(1, 0, "")
    If $iDirection <> 1 And $iDirection <> -1 Then Return SetError(2, 0, "")
   
    Local $iTotal_Items = _GUICtrlListView_GetItemCount($hListView)
    Local $iTotal_Columns = _GUICtrlListView_GetColumnCount($hListView)
   
    Local $iUbound = UBound($aSelected_Indices)-1, $iNum = 1, $iStep = 1
   
    Local $iCurrent_Index, $iUpDown_Index, $sCurrent_ItemText, $sUpDown_ItemText
    Local $iCurrent_CheckedState, $iUpDown_CheckedState
    Local $iImage_Current_Index, $iImage_UpDown_Index
   
    If ($iDirection = -1 And $aSelected_Indices = 0) Or _
      ($iDirection = 1 And $aSelected_Indices[$iUbound] = $iTotal_Items-1) Then Return SetError(3, 0, "")
   
    ControlListView($hListView, "", "", "SelectClear")
   
    If $iDirection = 1 Then
      $iNum = $iUbound
      $iUbound = 1
      $iStep = -1
    EndIf
   
    For $i = $iNum To $iUbound Step $iStep
      $iCurrent_Index = $aSelected_Indices[$i]
      $iUpDown_Index = $aSelected_Indices[$i]+1
      If $iDirection = -1 Then $iUpDown_Index = $aSelected_Indices[$i]-1
      
      $iCurrent_CheckedState = _GUICtrlListView_GetItemChecked($hListView, $iCurrent_Index)
      $iUpDown_CheckedState = _GUICtrlListView_GetItemChecked($hListView, $iUpDown_Index)
      
      _GUICtrlListView_SetItemSelected($hListView, $iUpDown_Index)
      
      For $j = 0 To $iTotal_Columns-1
            $sCurrent_ItemText = _GUICtrlListView_GetItemText($hListView, $iCurrent_Index, $j)
            $sUpDown_ItemText = _GUICtrlListView_GetItemText($hListView, $iUpDown_Index, $j)
            
            If _GUICtrlListView_GetImageList($hListView, 1) <> 0 Then
                $iImage_Current_Index = _GUICtrlListView_GetItemImage($hListView, $iCurrent_Index, $j)
                $iImage_UpDown_Index = _GUICtrlListView_GetItemImage($hListView, $iUpDown_Index, $j)
               
                _GUICtrlListView_SetItemImage($hListView, $iCurrent_Index, $iImage_UpDown_Index, $j)
                _GUICtrlListView_SetItemImage($hListView, $iUpDown_Index, $iImage_Current_Index, $j)
            EndIf
            
            _GUICtrlListView_SetItemText($hListView, $iUpDown_Index, $sCurrent_ItemText, $j)
            _GUICtrlListView_SetItemText($hListView, $iCurrent_Index, $sUpDown_ItemText, $j)
      Next
      
      _GUICtrlListView_SetItemChecked($hListView, $iUpDown_Index, $iCurrent_CheckedState)
      _GUICtrlListView_SetItemChecked($hListView, $iCurrent_Index, $iUpDown_CheckedState)
      
      _GUICtrlListView_SetItemSelected($hListView, $iUpDown_Index, 0)
    Next
   
    For $i = 1 To UBound($aSelected_Indices)-1
      $iUpDown_Index = $aSelected_Indices[$i]+1
      If $iDirection = -1 Then $iUpDown_Index = $aSelected_Indices[$i]-1
      _GUICtrlListView_SetItemSelected($hListView, $iUpDown_Index)
    Next
   
    Return 1
EndFunc

gzh888666 发表于 2011-10-1 22:00:23

AutoIt 3.3.0.0 好老的UDF

zcool321 发表于 2011-10-1 22:50:55

~!~就是一个上下~!~为什么不自己看帮助弄呢~

andyhu 发表于 2011-10-2 00:46:19

自己弄出来了,最近两天才开始研究,其实很简单的,多谢1楼帮助
页: [1]
查看完整版本: 怎样通过上下按钮来排序listview/listbox的顺序?