找回密码
 加入
搜索
查看: 1677|回复: 2

[GUI管理] [已解决]如何在调整listviewitem中的Item顺序

[复制链接]
发表于 2012-4-24 09:40:02 | 显示全部楼层 |阅读模式
本帖最后由 MicroBlue 于 2012-4-24 10:24 编辑

hi 大家好:

我这里有一个已经写好的Listviewitem,但是我想调整他们的顺序,看了很多函数,也没找对啊,大家有好的方法么?谢谢了!!!!



我想选中一个条目后,点击上,就能往前调一个位置,点击下,就能往下调一个位置。



问题已解决!一楼 _GUICtrlListView_MoveItemsSelected() 这个函数太棒了

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2012-4-24 10:14:29 | 显示全部楼层
现学现卖
#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <GuiListView.au3>
#include <SendMessage.au3>
$GUI = GUICreate('_GUICtrlListView_MoveItemsSelected', 300, 320)
$Up_Button = GUICtrlCreateButton("Up", 20, 20, 40, 24)
$Down_Button = GUICtrlCreateButton("Down", 70, 20, 40, 24)
$ListView = _GUICtrlListView_Create($GUI, "Column1|Column2", 20, 50, 260, 250, BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT), $WS_EX_CLIENTEDGE)
_GUICtrlListView_SetExtendedListViewStyle($ListView, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
For $i = 0 To 9
  _GUICtrlListView_AddItem($ListView, "Item " & $i + 1, Random(0, 2, 1))
  _GUICtrlListView_AddSubItem($ListView, $i, "SubItem " & $i + 1, 1, Random(0, 2, 1))
Next

$iRandom_1 = Random(0, 9, 1)
$iRandom_2 = Random(0, 9, 1)

_GUICtrlListView_SetItemChecked($ListView, $iRandom_1, 1)
_GUICtrlListView_SetItemSelected($ListView, $iRandom_1, 1)

_GUICtrlListView_SetItemChecked($ListView, $iRandom_2, 1)
_GUICtrlListView_SetItemSelected($ListView, $iRandom_2, 1)

_SendMessage($ListView, $LVM_SETCOLUMNWIDTH, 0, -1)
_SendMessage($ListView, $LVM_SETCOLUMNWIDTH, 1, -1)

ControlFocus($GUI, "", $ListView)

GUISetState()

While 1
  Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
    Exit
    Case $Up_Button
   _GUICtrlListView_MoveItemsSelected($ListView, -1)
   ControlFocus($GUI, "", $ListView)
        Case $Down_Button
   _GUICtrlListView_MoveItemsSelected($ListView, 1)
   ControlFocus($GUI, "", $ListView)
  EndSwitch
WEnd


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[1] = 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
 楼主| 发表于 2012-4-24 10:22:47 | 显示全部楼层
回复 2# 502762378


   太好了,你的这个函数太棒了,谢谢你!!!!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-30 13:18 , Processed in 0.082735 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表