Hallo,
ich würde gerne eine Listview refreshen, die Sortierung soll nach dem Refresh genauso sein wie zuvor und auch die Position der Scrollbar soll gleich bleiben.
Habt ihr eine Idee?
Danke schon mal im Vorraus.
Hier mal ein Beispiel:
C
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <ListViewConstants.au3>
#include <GuiListView.au3>
Opt("GUIOnEventMode", 1)
local $aNames[8][2]
$aNames[0][0] = "Mustermann"
$aNames[0][1] = "Frank"
$aNames[1][0] = "Arndt"
$aNames[1][1] = "Stephanie"
$aNames[2][0] = "Zeppelin"
$aNames[2][1] = "Konrad"
$aNames[3][0] = "Musterfrau"
$aNames[3][1] = "Paula"
$aNames[4][0] = "Berndt"
$aNames[4][1] = "Sigmund"
$aNames[5][0] = "Alonso"
$aNames[5][1] = "Stephan"
$aNames[6][0] = "Henning"
$aNames[6][1] = "Marc"
$aNames[7][0] = "Kaufmann"
$aNames[7][1] = "Olaf"
$Form1 = GUICreate("", 376, 200, 192, 124)
$ListView1 = GUICtrlCreateListView("", 140, 40, 230, 100)
_GUICTRLListView_AddColumn($ListView1,"Name","100")
_GUICTRLListView_AddColumn($ListView1,"Vorname","100")
_fillList()
$Button1 = GUICtrlCreateButton("Button1", 10, 40, 113, 33)
GUICtrlSetOnEvent (-1, "_refresh")
GUISetState(@SW_SHOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($ListView1)]
While 1
sleep(50)
WEnd
func _refresh()
$selected = _GUICtrlListView_GetSelectedIndices($ListView1)
_GUICTRLListView_DeleteAllItems($ListView1)
_fillList()
_GUICTRLListView_Setitemselected(GUICtrlGetHandle($ListView1),$selected,True,True)
endfunc
func _filllist()
for $i = 1 to 8
GUICtrlCreateListViewItem($aNames[random(1,8)][0] & "|" & $aNames[random(1,8)][1],$ListView1)
next
EndFunc
func _exit()
Exit
endfunc
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
$hWndListView = $listview1
If Not IsHWnd($listview1) Then $hWndListView = GUICtrlGetHandle($listview1)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
If ($hWndFrom = $hWndListView) And ($iCode = $LVN_COLUMNCLICK) Then
_GUICtrlListView_SimpleSort($hWndListView, $B_DESCENDING, DllStructGetData($tInfo, "SubItem"))
EndIf
EndFunc
Alles anzeigen