有关_GUICtrlListView_Create创建控制多选与排序的问题,请进来!(已解决)
本帖最后由 txm888 于 2012-6-26 00:15 编辑我发现用_GUICtrlListView_Create创建的控制不能设为多选和升降排序,而用GUICtrlListView创建的控制则能多选和升降排序,请问这是为什么?有哪位仁兄遇到过? 本帖最后由 netegg 于 2012-6-24 18:22 编辑
默认是: $LVS_REPORT(0x0001), $LVS_SINGLESEL(0x0004), $LVS_SHOWSELALWAYS(0x0008)
不过可能不太好整,不过倒是可以用另一种方式满足,选中的时候设置每行背景色,换项目的时候原行不变,新选行改变背景色就行了(http://www.autoitx.com/thread-15521-1-1.html)
如果lz有兴趣,用_sendmessage试试,可以在创建时搞定 本帖最后由 happytc 于 2012-6-24 21:01 编辑
回复 1# txm888
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>
Global $hListview
Global $aItemData = ["Name1|192.168.1.5|999999991|PC0|00112233FE", _
"Name2|192.168.1.4|999999993|PC2|00112233BD", _
"Name3|192.168.1.3|999999995|PC4|00112233AC", _
"Name4|192.168.1.2|999999992|PC1|00112233F0", _
"Name5|192.168.1.1|999999994|PC3|00112233E8", _
"Name6|192.168.1.6|999999996|PC6|00112233E9", _
"Name7|192.168.1.7|999999997|PC7|00112233EA", _
"Name8|192.168.1.8|999999998|PC8|00112233EB", _
"Name9|192.168.1.9|999999999|PC9|00112233EC", _
"Name0|192.168.1.0|999999990|PC10|00112233ED"]
_Main()
Func _Main()
Local $iExListViewStyle, $iExListViewStyle, $hGUI
Local $aColWidths =
$iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE)
$iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $LVS_EX_DOUBLEBUFFER)
$hGUI = GUICreate("ListView Sort", 920, 300)
$hListview = _GUICtrlListView_Create($hGUI, "Domain Device|IP Address|Serial Number|Description|Mac Address", 5, 5, 910, 250, $LVS_REPORT, $iExWindowStyle)
_GUICtrlListView_SetExtendedListViewStyle($hListview, $iExListViewStyle)
For $i = 0 To UBound($aColWidths) - 1
_GUICtrlListView_SetColumnWidth($hListview, $i, $aColWidths[$i])
Next
_GUICtrlListView_SetBkColor($hListview, 0xA6CAF0)
_GUICtrlListView_JustifyColumn($hListview, 4, 2)
_FillItems()
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
GUISetState()
_GUICtrlListView_RegisterSortCallBack($hListview, True, True)
While True
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
_GUICtrlListView_UnRegisterSortCallBack($hListview)
GUIDelete()
EndFunc
Func _FillItems()
Local $aSplit
For $i = 0 To UBound($aItemData) - 1
$aSplit = StringSplit($aItemData[$i], "|")
_GUICtrlListView_AddItem($hListview, $aSplit, -1, _GUICtrlListView_GetItemCount($hListview) )
For $j = 2 To $aSplit
_GUICtrlListView_AddSubItem($hListview, $i, $aSplit[$j], $j - 1)
Next
Next
EndFunc
Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iCode, $tNMHDR
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hListview
Switch $iCode
Case $LVN_COLUMNCLICK
Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
Local $iCol = DllStructGetData($tInfo, "SubItem")
_GUICtrlListView_SortItems($hWndFrom, $iCol)
EndSwitch
EndSwitch
Return $__LISTVIEWCONSTANT_GUI_RUNDEFMSG
EndFunc
回复 2# netegg
不好意思,今天才回来,感谢蛋蛋大师给的指引,不过,我试过了,多选可以,排序不行。。。小的级别不行 回复 3# happytc
很不错的一例,堪称完美,同时解决了该函数创建的控制实现多选与排序的问题,再次感谢,学习了
页:
[1]