Liste anzeigen in tabelle und alphabetisch sortieren

02/24/2014 17:32 lolkop#16
Quote:
Originally Posted by Shadow992 View Post
Und dann liest du die Datei ein und machst zuerst ein StringSplit nach @CRLF
und danach nach "|" und dann hast du deine Einträge auch auf mehrere Arrays verteilt.
noch einfacher wäre es wohl, auf das @crlf zu verzichten und alles direkt in einem schritt einzulesen.

beim einarbeiten ins gui dann einfach unnötige glieder überspringen

beispiel:
Code:
#include <GuiListView.au3>
; global variables
Global Const $stateIdle = "Idle", $stateAddEntry = "Adding Entrys"
Global $array[65532][4] ; [controlID][name,beschreibung,typ,nummer]
; main gui
$guiMain = GUICreate('GUI', 400, 400, Default, Default, 0x10C80000)
$listView = GUICtrlCreateListView("Name|Beschreibung|Typ|Nummer", 0, 0, 400, 360)
_GUICtrlListView_RegisterSortCallBack($listView)
$btnAdd = GUICtrlCreateButton('Add Entry', 0, 360, 200, 20)
$btnDel = GUICtrlCreateButton('Delete Entry', 200, 360, 200, 20)
$lblStatus = GUICtrlCreateLabel($stateIdle, 0, 380, 400, 20, 0x201)
; add info gui
$guiAddEntry = GUICreate('Add Entry', 200, 122, -1, -1, 0xC80000, -1, $guiMain)
GUICtrlCreateGroup('Name', 2, 0, 98, 45)
$inptName = GUICtrlCreateInput('', 7, 20, 88, 20)
GUICtrlCreateGroup('Beschreibung', 100, 0, 98, 45)
$inptBeschreibung = GUICtrlCreateInput('', 105, 20, 88, 20)
GUICtrlCreateGroup('Typ', 2, 50, 98, 45)
$inptTyp = GUICtrlCreateInput('', 7, 70, 88, 20)
GUICtrlCreateGroup('Nummer', 100, 50, 98, 45)
$inptNummer = GUICtrlCreateInput('', 105, 70, 88, 20)
$btnAddAdd = GUICtrlCreateButton('Add', 0, 98, 100, 20)
$btnCancel = GUICtrlCreateButton('Cancel', 100, 98, 100, 20)
LoadAll()

While True
	$msg = GUIGetMsg(1)
	Switch $msg[0]
		Case -3, $btnCancel
			If $msg[1] = $guiMain Then
				SaveAll()
				Exit
			EndIf
			GUISetState(@SW_HIDE, $msg[1])
		Case $listView
			_GUICtrlListView_SortItems($listView, GUICtrlGetState($listView))
		Case $btnAdd
			GUISetState(@SW_SHOW, $guiAddEntry)
		Case $btnDel
			DelEntry(GUICtrlRead($listView))
		Case $btnAddAdd
			If GUICtrlRead($inptName) And GUICtrlRead($inptBeschreibung) And GUICtrlRead($inptTyp) And GUICtrlRead($inptNummer) Then
				SetState($stateAddEntry)
				AddEntry(GUICtrlRead($inptName), GUICtrlRead($inptBeschreibung), GUICtrlRead($inptTyp), GUICtrlRead($inptNummer))
				GUISetState(@SW_HIDE, $msg[1])
				SetState($stateIdle)
			Else
				MsgBox(0, "Info", "Set all empty fields first!")
			EndIf
	EndSwitch
WEnd

Func AddEntry($name, $beschreibung, $typ, $nummer)
	Local $id = GUICtrlCreateListViewItem($name&'|'&$beschreibung&'|'&$typ&'|'&$nummer, $listView)
	$array[$id][0] = $name
	$array[$id][1] = $beschreibung
	$array[$id][2] = $typ
	$array[$id][3] = $nummer
EndFunc
Func DelEntry($id)
	If $id=0 Then
		MsgBox(0, "Info", "Select an Entry First")
		Return 0
	EndIf
	For $i=0 To 3
		$array[$id][$i]=''
	Next
	GUICtrlDelete($id)
EndFunc
Func SetState($string)
	GUICtrlSetData($lblStatus, $string)
EndFunc
Func LoadAll()
	SetState($stateAddEntry)
	Local $content = StringSplit(FileRead("content.txt"),'|')
	If $content[0]=1 Then Return False
	For $i=1 To $content[0] Step 4
		AddEntry($content[$i], $content[$i+1], $content[$i+2], $content[$i+3])
	Next
	SetState($stateIdle)
EndFunc
Func SaveAll()
	Local $content
	For $i=0 To 65531
		If $array[$i][0] Then $content&=$array[$i][0]&'|'&$array[$i][1]&'|'&$array[$i][2]&'|'&$array[$i][3]&'|'
	Next
	$hwnd = FileOpen("content.txt", 2)
	FileWrite($hwnd, StringTrimRight($content,1))
	FileClose($hwnd)
EndFunc