Hallo,
ich habe mehrere Fragen und Probleme mit ListView. Ich hoffe es ist OK hier zwei Beispiele in einem
Post unterzubringen. Damit es nicht so lang wird, habe ich die in eine Spoiler geschoben.
Beispiel A:
Man muss auf "Scan for Devices" klicken. Wenn man jetzt die ListView anschaut ohne
die Gruppen zu aktivieren, erkennt man dass die GridLines trotz _GUICtrlListView_BeginUpdate
von oben nach unten gelöscht werden. Eigentlich sollte das doch nicht passieren. Kann man
aber deutlich erkennen.
Fragen zu A:
- Ist das ein Bug(?) oder mach ich da was falsch (ggf. lasse ich das mit _GUICtrlListView_BeginUpdate weg).
- Kann man die Farbe der GRIDLINES ändern? (Cooperated Design des Unternehmens)
- Kann man die erste Spalte auch OHNE Icons darstellen, die anderen aber schon? Würde in der
ersten Spalte gerne die Icons (hier ein Freiraum) weghaben.
Spoiler anzeigen
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <ListViewConstants.au3>
Opt("GUIOnEventMode", 1)
[/autoit] [autoit][/autoit] [autoit]; ===============================================================================================================================
; GUI
; ===============================================================================================================================
$Main = GUICreate("Main", 689, 485, -1, -1)
GUICtrlSetOnEvent(-1, "_Exit")
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
; ===============================================================================================================================
; Listview
; ===============================================================================================================================
Local $iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE)
Local $iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES, $LVS_EX_FLATSB, $LVS_EX_GRIDLINES, $LVS_EX_SIMPLESELECT, $LVS_EX_TWOCLICKACTIVATE,$LVS_EX_SUBITEMIMAGES)
$hListView = GUICtrlCreateListView("", 8, 8, 674, 337, -1, $iExWindowStyle)
GUICtrlSetBkColor(-1, 0xDEDEDD)
_GUICtrlListView_SetExtendedListViewStyle($hListView, $iExListViewStyle)
; Add columns
_GUICtrlListView_AddColumn($hListView, "Device 0", 60)
_GUICtrlListView_AddColumn($hListView, "Device A", 120)
_GUICtrlListView_AddColumn($hListView, "Device B", 120)
_GUICtrlListView_AddColumn($hListView, "Actual C", 120)
_GUICtrlListView_AddColumn($hListView, "Note", 200)
; Create Groups
_GUICtrlListView_EnableGroupView($hListView, False)
_GUICtrlListView_InsertGroup($hListView, -1, 1, "Gruppe A")
_GUICtrlListView_InsertGroup($hListView, -1, 2, "Gruppe B")
_GUICtrlListView_InsertGroup($hListView, -1, 3, "Gruppe C")
_GUICtrlListView_InsertGroup($hListView, -1, 4, "Gruppe D")
_GUICtrlListView_SetGroupInfo($hListView, 1, "Gruppe A",0,$LVGS_COLLAPSIBLE)
_GUICtrlListView_SetGroupInfo($hListView, 2, "Gruppe B",0,$LVGS_COLLAPSIBLE)
_GUICtrlListView_SetGroupInfo($hListView, 3, "Gruppe C",0,$LVGS_COLLAPSIBLE)
_GUICtrlListView_SetGroupInfo($hListView, 4, "Gruppe D",0,$LVGS_COLLAPSIBLE)
$hImage = _GUIImageList_Create(16,16,5,3)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 50)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 12)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 176)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 144)
_GUICtrlListView_SetImageList($hListView, $hImage, 1)
; ===============================================================================================================================
; Button and Checkbox
; ===============================================================================================================================
GUICtrlCreateButton("Scan for Devices", 6, 365, 140, 35)
GUICtrlSetOnEvent(-1, "_Scan")
GUICtrlCreateButton("Exit", 543, 365, 140, 35)
GUICtrlSetOnEvent(-1, "_Exit")
Global $hCheckBox = GUICtrlCreateCheckbox("Display in Groups",8,410)
GUICtrlSetOnEvent(-1, "_GroupView")
GUISetState(@SW_SHOW)
[/autoit] [autoit][/autoit] [autoit]While Sleep(100)
WEnd
Func _Scan()
Local $avSmartline[5] = [1,"Gruppe A","Gruppe B","Gruppe C","Gruppe D"]
Local $sTemp, $sFWDevice, $sFWHex
_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($hListView))
_GUICtrlListView_BeginUpdate($hListView) ; Bug mit GRIDLINES
Local $kCounter = -1
For $iCounter = 0 To 15
; Sleep: WICHTIG! Ist nur zur Simulation um das Script zu testen. Wird später durch eine RS232
; Kommunikation ersetzt, die ca. 100 bis 150 ms dauert. So sieht man den Bug (?) mit GRIDLINES.
Sleep(200)
$sTemp = $avSmartline[Random(1,4,1)]
$sFWDevice = "1.0." & Random(1,4,1)
$sFWHex = "1.0." & Random(1,4,1)
If $sTemp <> "" Then
$kCounter = $kCounter + 1
_GUICtrlListView_AddItem($hListView , $iCounter+1, -1)
_GUICtrlListView_SetItemGroupID($hListView, $kCounter, _ArraySearch($avSmartline,$sTemp,1,4))
_GUICtrlListView_AddSubItem($hListView, $kCounter, $sTemp , 1)
_GUICtrlListView_AddSubItem($hListView, $kCounter, $sFWDevice , 2, 1)
If $sFWDevice = $sFWHex Then
_GUICtrlListView_AddSubItem($hListView, $kCounter, $sFWHex , 3, 3)
Else
_GUICtrlListView_AddSubItem($hListView, $kCounter, $sFWHex , 3, 2)
EndIf
EndIf
Next
_GUICtrlListView_EndUpdate($hListView) ; Bug mit GRIDLINES
EndFunc
Func _GroupView()
If GUICtrlRead($hCheckBox) = $GUI_CHECKED Then
_GUICtrlListView_EnableGroupView($hListView, True)
Else
_GUICtrlListView_EnableGroupView($hListView, False)
EndIf
EndFunc
Func _Exit()
GUIDelete()
Exit
EndFunc ;-->_Exit
Beispiel B:
Man muss auf "Scan for Devices" klicken. Ich habe versucht die Einträge sortieren zu
lassen mit den Beispiel aus der AutoIt Hilfe. Jetzt treten zwei Fehler auf:
1. Fehler: Wenn ich auf eine der Spalten klicke, wird automatisch beim ersten Eintrag
(also wo in der 1. Spalte die "1" steht) CHECKED gemacht. Soll aber nicht.
2. Fehler: Die Icons in der Spalte "Actual C" werden NICHT sortiert.
Spoiler anzeigen
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <ListViewConstants.au3>
Opt("GUIOnEventMode", 1)
[/autoit] [autoit][/autoit] [autoit]; ===============================================================================================================================
; GUI
; ===============================================================================================================================
$Main = GUICreate("Main", 689, 485, -1, -1)
GUICtrlSetOnEvent(-1, "_Exit")
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
; ===============================================================================================================================
; Listview
; ===============================================================================================================================
Local $iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE)
Local $iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES, $LVS_EX_FLATSB, $LVS_EX_GRIDLINES, $LVS_EX_SIMPLESELECT, $LVS_EX_TWOCLICKACTIVATE,$LVS_EX_SUBITEMIMAGES)
$hListView = GUICtrlCreateListView("", 8, 8, 674, 337, -1, $iExWindowStyle)
_GUICtrlListView_SetExtendedListViewStyle($hListView, $iExListViewStyle)
; Add columns
_GUICtrlListView_AddColumn($hListView, "Device 0", 60)
_GUICtrlListView_AddColumn($hListView, "Device A", 120)
_GUICtrlListView_AddColumn($hListView, "Device B", 120)
_GUICtrlListView_AddColumn($hListView, "Actual C", 120)
_GUICtrlListView_AddColumn($hListView, "Note", 200)
; Create Groups
_GUICtrlListView_EnableGroupView($hListView, False)
_GUICtrlListView_InsertGroup($hListView, -1, 1, "Gruppe A")
_GUICtrlListView_InsertGroup($hListView, -1, 2, "Gruppe B")
_GUICtrlListView_InsertGroup($hListView, -1, 3, "Gruppe C")
_GUICtrlListView_InsertGroup($hListView, -1, 4, "Gruppe D")
_GUICtrlListView_SetGroupInfo($hListView, 1, "Gruppe A",0,$LVGS_COLLAPSIBLE)
_GUICtrlListView_SetGroupInfo($hListView, 2, "Gruppe B",0,$LVGS_COLLAPSIBLE)
_GUICtrlListView_SetGroupInfo($hListView, 3, "Gruppe C",0,$LVGS_COLLAPSIBLE)
_GUICtrlListView_SetGroupInfo($hListView, 4, "Gruppe D",0,$LVGS_COLLAPSIBLE)
$hImage = _GUIImageList_Create(16,16,5,3)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 50)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 12)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 176)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 144)
_GUICtrlListView_SetImageList($hListView, $hImage, 1)
; ===============================================================================================================================
; Button and Checkbox
; ===============================================================================================================================
GUICtrlCreateButton("Scan for Devices", 6, 365, 140, 35)
GUICtrlSetOnEvent(-1, "_Scan")
GUICtrlCreateButton("Exit", 543, 365, 140, 35)
GUICtrlSetOnEvent(-1, "_Exit")
Global $hCheckBox = GUICtrlCreateCheckbox("Display in Groups",8,410)
GUICtrlSetOnEvent(-1, "_GroupView")
GUISetState(@SW_SHOW)
[/autoit] [autoit][/autoit] [autoit]GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ; NEU
Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($hListView)] ; NEU
While Sleep(100)
WEnd
Func _Scan()
Local $avSmartline[5] = [1,"Gruppe A","Gruppe B","Gruppe C","Gruppe D"]
Local $sTemp, $sFWDevice, $sFWHex
_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($hListView))
[/autoit] [autoit][/autoit] [autoit]Local $kCounter = -1
For $iCounter = 0 To 15
; Sleep: WICHTIG! Ist nur zur Simulation um das Script zu testen. Wird später durch eine RS232
; Kommunikation ersetzt, die ca. 100 bis 150 ms dauert. So sieht man den Bug (?) mit GRIDLINES.
Sleep(200)
$sTemp = $avSmartline[Random(1,4,1)]
$sFWDevice = "1.0." & Random(1,4,1)
$sFWHex = "1.0." & Random(1,4,1)
If $sTemp <> "" Then
$kCounter = $kCounter + 1
_GUICtrlListView_AddItem($hListView , $iCounter+1, -1)
_GUICtrlListView_SetItemGroupID($hListView, $kCounter, _ArraySearch($avSmartline,$sTemp,1,4))
_GUICtrlListView_AddSubItem($hListView, $kCounter, $sTemp , 1)
_GUICtrlListView_AddSubItem($hListView, $kCounter, $sFWDevice , 2, 1)
If $sFWDevice = $sFWHex Then
_GUICtrlListView_AddSubItem($hListView, $kCounter, $sFWHex , 3, 3)
Else
_GUICtrlListView_AddSubItem($hListView, $kCounter, $sFWHex , 3, 2)
EndIf
EndIf
Next
EndFunc
Func _GroupView()
If GUICtrlRead($hCheckBox) = $GUI_CHECKED Then
_GUICtrlListView_EnableGroupView($hListView, True)
Else
_GUICtrlListView_EnableGroupView($hListView, False)
EndIf
EndFunc
Func _Exit()
GUIDelete()
Exit
EndFunc ;-->_Exit
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
$hWndListView = $hListView
If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
$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
Danke
Stefan