ListView reagiert nicht

  • Hallo Leute,
    ich hab eine Listview erstellt, die ihre Daten aus einer Excel- Liste bekommt. Leider reagiert die Listview nicht mehr, wenn es darum geht, sie zu aktualisieren.
    Beim Start des Programmes pack ich mir dazu die Zellen der Excel-Liste in ein mehrdimensionales Array und aktualiesiere die Listview mit _GUICtrlListView_AddArray. Das funktioniert auch. Leider kann ich die Liste weder sortieren mit _GUICtrlListView_SortItems($list1, GUICtrlGetState($list1)) noch lassen sich mit _GUICtrlListView_DeleteAllItems($list1) die Daten aus der Liste löschen.
    Hat jemand schon Erfahrungen gemacht damit?
    Kann es sein, dass die Variable der Listview, in diesem Fall $list1 nicht global sein darf? Denn das aktualisieren hat schonmal funktioniert, aber irgendwann nicht mehr.
    Könnte mir jemand helfen?

    • Offizieller Beitrag

    Kannst du dein Script posten. Es ist einfacher den Fehler zu finden wenn man testen kann.

  • Da könnte ich Ärger mit meiner Firma bekommen wenn ich es poste, ist nämlich nen Tool für die Arbeit...würde ich gerne, weiß ja auch das es einfacher geht. Nehm hier oft die Suche und schau ob mir das Forum ohne zu posten weiter helfen kann, und dort sieht man dann ja, dass es leichter geht wenn man testen kann. Aber ich hab gerade gesehen, du wohnst in FFM. Ich arbeite hier in Niedereschbach. Vielleicht gibt es da ne Möglichkeit?
    Die Excel-Liste kann ich ja auch schlecht posten...
    Trotzdem bin ich über jeden Tipp sehr dankbar...Schlag mich nämlich schon seit vier Stunden mit dem Problem rum und dachte mir kann jemand helfen, weil die Listview ja grundsätzlich nicht reagiert, weder auf sortieren noch auf Einträge löschen.

  • vielen Dank für diesen Tipp...bin seit heute früh um sechs im Büro, wird langsam Zeit Feierabend zu machen, aber gleich morgen früh werd ich das ausprobieren. Vielen Dank an dich...Schönen Abend...Ich sag bescheid ob ich es hinbekommen hab...
    Edit:
    Geiler Typ!!!
    Hat mir keine Ruhe gelassen, hab das noch schnell ausgetestet. Das löschen der Liste funktioniert. leider das sortieren nicht. Hab ich so gemacht:

    Spoiler anzeigen
    [autoit]


    Case $msg = $list1
    MsgBox(0,"",GUICtrlGetState($list1))
    $list1 = GUICtrlGetHandle($list1)
    _GUICtrlListView_SortItems($list1, GUICtrlGetState($list1))

    [/autoit]

    Einmal editiert, zuletzt von derplatzwart (15. Januar 2009 um 22:01)

    • Offizieller Beitrag

    Hier mal ein Bsp. für SimpleSort per Spaltenklick.

    Spoiler anzeigen
    [autoit]

    #include <GuiConstantsEx.au3>
    #include <GuiListView.au3>
    #include <WindowsConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    $gui = GUICreate('Test LV-Sort')
    $hListView = GUICtrlCreateListView('Spalte 1|Spalte 2', 10, 10, 300, 200)
    For $i = 1 To 15
    GUICtrlCreateListViewItem(Chr(Random(65,90)) & '|' & Chr(Random(65,90)), $hListView)
    Next
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($hListView)]

    [/autoit] [autoit][/autoit] [autoit]

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    [/autoit] [autoit][/autoit] [autoit]

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    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)

    [/autoit] [autoit][/autoit] [autoit]

    $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)
    _GUICtrlListView_SimpleSort($hWndListView, $B_DESCENDING, DllStructGetData($tInfo, "SubItem"))
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_NOTIFY

    [/autoit]

    Edit:
    Und hier mit _GUICtrlListView_RegisterSortCallBack:

    Spoiler anzeigen
    [autoit]

    #include <GuiConstantsEx.au3>
    #include <GuiListView.au3>
    #include <WindowsConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    $gui = GUICreate('Test LV-Sort')
    $hListView = GUICtrlCreateListView('Spalte 1|Spalte 2', 10, 10, 300, 200)
    For $i = 1 To 15
    GUICtrlCreateListViewItem(Chr(Random(65,90)) & '|' & Chr(Random(65,90)), $hListView)
    Next
    $hListView = GUICtrlGetHandle($hListView)
    $b1 = GUICtrlCreateButton('sort 1', 20, 240, 65, 20)
    $b2 = GUICtrlCreateButton('sort 2', 100, 240, 65, 20)

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    _GUICtrlListView_RegisterSortCallBack($hListView)

    [/autoit] [autoit][/autoit] [autoit]

    Do
    $msg = GUIGetMsg()
    Switch $msg
    Case $b1
    _GUICtrlListView_SortItems($hListView, 0)
    Case $b2
    _GUICtrlListView_SortItems($hListView, 1)
    EndSwitch
    Until $msg = $GUI_EVENT_CLOSE
    _GUICtrlListView_UnRegisterSortCallBack($hListView)

    [/autoit]
    • Offizieller Beitrag

    BugFix kannst du mir nen Tipp geben wo ich mehr über WM_NOTIFY erfahre ? Oder besser wie das ganze funktioniert .

    • Offizieller Beitrag

    Hier mal alle möglichen Events beim ListView, die du mit WM_NOTIFY abfangen kannst.
    Die Rückgabeparameter habe ich alle in ein Array gepackt.
    Näheres zu den MessageCodes (WM_NOTIFY, WM_COMMAND etc.) findest du bei MSDN.

    Spoiler anzeigen
    [autoit]

    Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView
    $hWndListView = $hListView
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)

    [/autoit] [autoit][/autoit] [autoit]

    $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
    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
    Local $aInfo[11] = [$hWndFrom, _
    $iIDFrom, _
    $iCode, _
    DllStructGetData($tInfo, "Index"), _
    DllStructGetData($tInfo, "SubItem"), _
    DllStructGetData($tInfo, "NewState"), _
    DllStructGetData($tInfo, "OldState"), _
    DllStructGetData($tInfo, "Changed"), _
    DllStructGetData($tInfo, "ActionX"), _
    DllStructGetData($tInfo, "ActionY"), _
    DllStructGetData($tInfo, "Param")]
    ;~ _ColumnClick($aInfo)
    Case $LVN_DELETEITEM ; An item is about to be deleted
    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
    Local $aInfo[11] = [$hWndFrom, _
    $iIDFrom, _
    $iCode, _
    DllStructGetData($tInfo, "Index"), _
    DllStructGetData($tInfo, "SubItem"), _
    DllStructGetData($tInfo, "NewState"), _
    DllStructGetData($tInfo, "OldState"), _
    DllStructGetData($tInfo, "Changed"), _
    DllStructGetData($tInfo, "ActionX"), _
    DllStructGetData($tInfo, "ActionY"), _
    DllStructGetData($tInfo, "Param")]
    ;~ _ItemDeleted($aInfo)
    Case $LVN_HOTTRACK ; Sent by a list-view control when the user moves the mouse over an item
    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
    Local $aInfo[11] = [$hWndFrom, _
    $iIDFrom, _
    $iCode, _
    DllStructGetData($tInfo, "Index"), _
    DllStructGetData($tInfo, "SubItem"), _
    DllStructGetData($tInfo, "NewState"), _
    DllStructGetData($tInfo, "OldState"), _
    DllStructGetData($tInfo, "Changed"), _
    DllStructGetData($tInfo, "ActionX"), _
    DllStructGetData($tInfo, "ActionY"), _
    DllStructGetData($tInfo, "Param")]
    Return 0 ; allow the list view to perform its normal track select processing.
    ;Return 1 ; the item will not be selected.
    ;~ _HottTrackItem($aInfo)
    Case $LVN_KEYDOWN ; A key has been pressed
    Local $tInfo = DllStructCreate($tagNMLVKEYDOWN, $ilParam)
    Local $aInfo[5] = [$hWndFrom, _
    $iIDFrom, _
    $iCode, _
    DllStructGetData($tInfo, "VKey"), _
    DllStructGetData($tInfo, "KeyFlags")]
    ;~ _KeyDown($aInfo)
    Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
    Local $aInfo[12] = [$hWndFrom, _
    $iIDFrom, _
    $iCode, _
    DllStructGetData($tInfo, "Index"), _
    DllStructGetData($tInfo, "SubItem"), _
    DllStructGetData($tInfo, "NewState"), _
    DllStructGetData($tInfo, "OldState"), _
    DllStructGetData($tInfo, "Changed"), _
    DllStructGetData($tInfo, "ActionX"), _
    DllStructGetData($tInfo, "ActionY"), _
    DllStructGetData($tInfo, "lParam"), _
    DllStructGetData($tInfo, "KeyFlags")]
    _LeftClick($aInfo)
    Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
    Local $aInfo[12] = [$hWndFrom, _
    $iIDFrom, _
    $iCode, _
    DllStructGetData($tInfo, "Index"), _
    DllStructGetData($tInfo, "SubItem"), _
    DllStructGetData($tInfo, "NewState"), _
    DllStructGetData($tInfo, "OldState"), _
    DllStructGetData($tInfo, "Changed"), _
    DllStructGetData($tInfo, "ActionX"), _
    DllStructGetData($tInfo, "ActionY"), _
    DllStructGetData($tInfo, "lParam"), _
    DllStructGetData($tInfo, "KeyFlags")]
    ;~ _LeftDblClick($aInfo)
    Case $NM_KILLFOCUS ; The control has lost the input focus
    Local $aInfo[3] = [$hWndFrom, _
    $iIDFrom, _
    $iCode]
    ;~ _LostFocus($aInfo)
    Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the right mouse button
    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
    Local $aInfo[12] = [$hWndFrom, _
    $iIDFrom, _
    $iCode, _
    DllStructGetData($tInfo, "Index"), _
    DllStructGetData($tInfo, "SubItem"), _
    DllStructGetData($tInfo, "NewState"), _
    DllStructGetData($tInfo, "OldState"), _
    DllStructGetData($tInfo, "Changed"), _
    DllStructGetData($tInfo, "ActionX"), _
    DllStructGetData($tInfo, "ActionY"), _
    DllStructGetData($tInfo, "lParam"), _
    DllStructGetData($tInfo, "KeyFlags")]
    ; Return 1 ; not to allow the default processing
    Return 0 ; allow the default processing
    ;~ _RightClick($aInfo)
    Case $NM_RDBLCLK ; Sent by a list-view control when the user double-clicks an item with the right mouse button
    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
    Local $aInfo[12] = [$hWndFrom, _
    $iIDFrom, _
    $iCode, _
    DllStructGetData($tInfo, "Index"), _
    DllStructGetData($tInfo, "SubItem"), _
    DllStructGetData($tInfo, "NewState"), _
    DllStructGetData($tInfo, "OldState"), _
    DllStructGetData($tInfo, "Changed"), _
    DllStructGetData($tInfo, "ActionX"), _
    DllStructGetData($tInfo, "ActionY"), _
    DllStructGetData($tInfo, "lParam"), _
    DllStructGetData($tInfo, "KeyFlags")]
    ;~ _RightDblClick($aInfo)
    Case $NM_RETURN ; The control has the input focus and that the user has pressed the ENTER key
    Local $aInfo[3] = [$hWndFrom, _
    $iIDFrom, _
    $iCode]
    ;~ _InputFocusReturn($aInfo)
    Case $NM_SETFOCUS ; The control has received the input focus
    Local $aInfo[3] = [$hWndFrom, _
    $iIDFrom, _
    $iCode]
    ;~ _SetFocus($aInfo)
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_NOTIFY

    [/autoit]
    • Offizieller Beitrag

    Ich danke dir. Werde mich mal damit genauer beschäftigen.

    • Offizieller Beitrag

    Ups, da werd ich ja Wochenlag mit zu kämpfen haben. ;( Oder eher Monate wenn ich die ganzen Messagecodes sehe . :S

    • Offizieller Beitrag

    Danke hab ich schon bei MSDN gefunden. Über die Notify´s der einzelnen Controls kann man auch in den Constanten-au3´s unter #NOTIFICATIONS# was erfahren .

  • Hallo Leute,

    ich hab ein script von bugfix benutzt um mit meiner Listview-Geschichte weiter zu kommen, hat auch gefunzt. allerdings hab ich zwei Probleme, ich möchte gerne mehrere Listviews mit derselben Func sortieren und ich möchte gerne mit einem Doppelclick auf ein Item die Zeile bearbeiten.
    Ich füg mal meinen Quelltext ein. Wenn einer einen Vorschlag hätte wäre ich sehr dankbar.

    Spoiler anzeigen
    [autoit]


    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #Include <Array.au3>
    #Include <File.au3>
    #Include <GuiListView.au3>
    #Include <GuiTab.au3>
    #Include <Date.au3>
    #Include <string.au3>
    #include <ProgressConstants.au3>
    #include <ButtonConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt('MustDeclareVars', 1)

    [/autoit] [autoit][/autoit] [autoit]

    ; globale GUIvariablen
    Global $listg1, $listg2, $listg3, $listg4, $listg5, $listg6, $listg7, $listg8
    ; globale Datenvariablen
    Global $NEdata[10],$listg1data[1],$listg2data[1],$listsend
    ; globale Hilfsvariablen
    ; fremd
    Global $B_DESCENDING,$data[1]

    [/autoit] [autoit][/autoit] [autoit]

    Main()
    Func Main()

    [/autoit] [autoit][/autoit] [autoit]

    ;GUIvariablen

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ;Datenvariablen

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ;Hilfsvariablen
    Local $msg

    [/autoit] [autoit][/autoit] [autoit]

    ;EdO___________erstellen der Oberfläche ___________________________________________________________

    [/autoit] [autoit][/autoit] [autoit]

    GUICreate("Test", 800, 540,0,0)
    $listg1 = GUICtrlCreateListView('Spalte 1|Spalte 2', 10, 10, 300, 200)
    For $i = 1 To 15
    GUICtrlCreateListViewItem(Chr(Random(65,90)) & '|' & Chr(Random(65,90)), $listg1)
    Next
    $listg2 = GUICtrlCreateListView('Spalte 1|Spalte 2', 410, 10, 300, 200)
    For $i = 1 To 15
    GUICtrlCreateListViewItem(Chr(Random(65,90)) & '|' & Chr(Random(65,90)), $listg2)
    Next
    GUISetState()
    ;EdO ende__________________________________________________________________________________________
    ; WMN_____________ Vorraussetzung für WM_NOTIFY ___________________________________________________
    $B_DESCENDING = _GUICtrlListView_GetColumnCount($listg1)
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
    ; WMN Ende ________________________________________________________________________________________
    ; WSE ________________ while-Schleife zum erhalten der Oberfläche _________________________________
    While 1
    $msg = GUIGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
    ExitLoop
    Case $msg = $listg1
    ;$listsend = 1
    ;MsgBox(0,"",$listsend)
    EndSelect
    WEnd
    GUIDelete()

    EndFunc ;Main

    [/autoit] [autoit][/autoit] [autoit]

    ; ___________ die ungeliebte WM_NOTIFY Funktion ___________________________________________
    ; ___________ sorgt mittels WindowsFunktionen für das Abfragen der Aktion an der ListView
    Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo, $aInfo[12]
    Local $help ;testweise

    [/autoit] [autoit][/autoit] [autoit]

    $hWndListView = $listg1
    If Not IsHWnd($listg1) Then $hWndListView = GUICtrlGetHandle($listg1)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")

    [/autoit] [autoit][/autoit] [autoit]

    Switch $hWndFrom
    Case $hWndListView
    Switch $iCode
    Case $LVN_COLUMNCLICK ; A column was clicked
    $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
    _GUICtrlListView_SimpleSort($hWndListView, $B_DESCENDING, DllStructGetData($tInfo, "SubItem"))
    Case $NM_RDBLCLK
    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
    $aInfo[12] = [$hWndFrom, _
    $iIDFrom, _
    $iCode, _
    DllStructGetData($tInfo, "Index"), _
    DllStructGetData($tInfo, "SubItem"), _
    DllStructGetData($tInfo, "NewState"), _
    DllStructGetData($tInfo, "OldState"), _
    DllStructGetData($tInfo, "Changed"), _
    DllStructGetData($tInfo, "ActionX"), _
    DllStructGetData($tInfo, "ActionY"), _
    DllStructGetData($tInfo, "lParam"), _
    DllStructGetData($tInfo, "KeyFlags")]
    _ArrayDisplay($aInfo)
    ;MsgBox(0,"","Test")
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_NOTIFY

    [/autoit]

    nicht über die includes wundern...