那片叶子 发表于 2012-2-25 11:10:20

ListView编号排序问题

本帖最后由 那片叶子 于 2012-2-25 11:11 编辑

Func refresh()
      _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($GUI_ListBox))         ;修改指定控件的数据
      $var = IniReadSectionNames($dir)   ;从某标准配置文件(*.ini)中读取所有字段的信息.
      If @error Then
                MsgBox(4096, "", "发生错误,可能目标文件并非标准的INI文件.")
      Else
                For $i = 1 To $var
                                                Global $vaa=IniRead($dir, $var[$i], "a", "Not Found")
                                                Global $vab=IniRead($dir, $var[$i], "b", "Not Found")
                                                Global $vac=IniRead($dir, $var[$i], "c", "Not Found")
                                                Global $vad=IniRead($dir, $var[$i], "d", "Not Found")
                                                Global $vae=IniRead($dir, $var[$i], "e", "Not Found")
                                                Global $vaf=IniRead($dir, $var[$i], "f", "Not Found")
                                                Global $vag=IniRead($dir, $var[$i], "g", "Not Found")
                                                Global $vah=IniRead($dir, $var[$i], "h", "Not Found")
                                                Global $vai=IniRead($dir, $var[$i], "i", "Not Found")
                                                Global $vaj=IniRead($dir, $var[$i], "j", "Not Found")
                                                GUICtrlCreateListViewItem($vaa&"|"&$vab&"|"&$vac&"|"&$vad&"|"&$vae&"|"&$vaf&"|"&$vag&"|"&$vah&"|"&$vai&"|"&$vaj, $GUI_ListBox)
                                                ;修改指定控件的数据.从某标准配置文件(*.ini)中读取某个数值
                          Next
      EndIf
        EndFunc 我这样读取内容
$vaa=IniRead($dir, $var[$i], "a", "Not Found")
是读取编号 ,1,2,3.....

如图,如何编号按顺序排列啊

jxpxfeiw 发表于 2012-2-25 13:54:00

看看帮助文件里的_GUICtrlListView_SimpleSort函数吧

haijie1223 发表于 2012-2-25 18:32:38

#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>
$Debug_LV = False ;<<<<<<<<<+++
Global $ListView, $B_DESCENDING
_Example1()
Func _Example1()
Local $iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE);<<<<<<<<<+++
Local $iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $LVS_EX_DOUBLEBUFFER);<<<<<<<<<+++
GUICreate('升级或降序', 633, 454, 192, 114)
$ListView = GUICtrlCreateListView("", 10,10, 630, 450)
GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES);<<<<<<<<<+++
GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT);<<<<<<<<<+++
_GUICtrlListView_AddColumn($ListView, "自动编号", 100)
_GUICtrlListView_AddColumn($ListView, "数字", 100)
_GUICtrlListView_AddColumn($ListView, "转换", 100)
_GUICtrlListView_AddColumn($ListView, "备注", 100)
_GUICtrlListView_JustifyColumn($ListView, 0, 2)
_GUICtrlListView_JustifyColumn($ListView, 1, 2)
_GUICtrlListView_JustifyColumn($ListView, 2, 2)
_GUICtrlListView_JustifyColumn($ListView, 3, 2)
GUICtrlCreateListViewItem("1|5|e|", $ListView)
GUICtrlCreateListViewItem("2|3|ee|", $ListView)
GUICtrlCreateListViewItem("3|8|eg|", $ListView)
GUICtrlCreateListViewItem("4|7|eg|", $ListView)
GUICtrlCreateListViewItem("5|6|ej|", $ListView)
GUICtrlCreateListViewItem("6|5|ek|", $ListView)
GUICtrlCreateListViewItem("7|2|le|", $ListView)
GUICtrlCreateListViewItem("8|1|je|", $ListView)

GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY");<<<<<<<<<+++
Global $B_DESCENDING;<<<<<<<<<+++

   Do;<<<<<<<<<+++
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam);<<<<<<<<<+++
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
$hWndListView = $ListView
If Not IsHWnd($ListView) Then $hWndListView = GUICtrlGetHandle($ListView)

$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
   Case $hWndListView
    Switch $iCode
   Case $LVN_COLUMNCLICK ; A column was clicked
      $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
      _DebugPrint("$LVN_COLUMNCLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
      "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
      "-->Code:" & @TAB & $iCode & @LF & _
      "-->Item:" & @TAB & DllStructGetData($tInfo, "Item") & @LF & _
      "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _
      "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _
      "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _
      "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _
      "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _
      "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _
      "-->Param:" & @TAB & DllStructGetData($tInfo, "Param"))
      _GUICtrlListView_SimpleSort($hWndListView, $B_DESCENDING, DllStructGetData($tInfo, "SubItem"))
      ; No return value
   Case $LVN_KEYDOWN ; A key has been pressed
      $tInfo = DllStructCreate($tagNMLVKEYDOWN, $ilParam)
      _DebugPrint("$LVN_KEYDOWN" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
      "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
      "-->Code:" & @TAB & $iCode & @LF & _
      "-->VKey:" & @TAB & DllStructGetData($tInfo, "VKey") & @LF & _
      "-->Flags:" & @TAB & DllStructGetData($tInfo, "Flags"))
      ; No return value
   Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
      $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
      _DebugPrint("$NM_CLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
      "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
      "-->Code:" & @TAB & $iCode & @LF & _
      "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @LF & _
      "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _
      "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _
      "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _
      "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _
      "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _
      "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _
      "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @LF & _
      "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))
      ; No return value
   Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
      $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
      _DebugPrint("$NM_DBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
      "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
      "-->Code:" & @TAB & $iCode & @LF & _
      "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @LF & _
      "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _
      "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _
      "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _
      "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _
      "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _
      "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _
      "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @LF & _
      "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))
      ; No return value
   Case $NM_KILLFOCUS ; The control has lost the input focus
      _DebugPrint("$NM_KILLFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
      "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
      "-->Code:" & @TAB & $iCode)
      ; No return value
   Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the right mouse button
      $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
      _DebugPrint("$NM_RCLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
      "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
      "-->Code:" & @TAB & $iCode & @LF & _
      "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @LF & _
      "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _
      "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _
      "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _
      "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _
      "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _
      "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _
      "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @LF & _
      "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))
      ;Return 1 ; not to allow the default processing
      Return 0 ; allow the default processing
   Case $NM_RDBLCLK ; Sent by a list-view control when the user double-clicks an item with the right mouse button
      $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
      _DebugPrint("$NM_RDBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
      "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
      "-->Code:" & @TAB & $iCode & @LF & _
      "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @LF & _
      "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _
      "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _
      "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _
      "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _
      "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _
      "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _
      "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @LF & _
      "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))
      ; No return value
   Case $NM_RETURN ; The control has the input focus and that the user has pressed the ENTER key
      _DebugPrint("$NM_RETURN" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
      "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
      "-->Code:" & @TAB & $iCode)
      ; No return value
   Case $NM_SETFOCUS ; The control has received the input focus
      _DebugPrint("$NM_SETFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
      "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
      "-->Code:" & @TAB & $iCode)
      ; No return value
    EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _DebugPrint($s_text, $line = @ScriptLineNumber)
ConsoleWrite( _
    "!===========================================================" & @LF & _
    "+======================================================" & @LF & _
    "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
    "+======================================================" & @LF)
EndFunc   ;==>_DebugPrint

虎虎虎 发表于 2012-2-25 20:20:35

发哥好厉害,支持学习。
页: [1]
查看完整版本: ListView编号排序问题