YoannMorl Posted November 21, 2012 Posted November 21, 2012 Hi, I'd like to display a table with data filled from an Array in a GUI. Displaying an array is not a problem but how to do to have an table that i can sort when i click on a column and to give name to columns ? Could you show me the way please ? Thanks.
water Posted November 21, 2012 Posted November 21, 2012 Use a ListView control to display the array and add column headings. An example how to do a simple sort can be found here (function _GUICtrlListView_SimpleSort) My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
water Posted November 21, 2012 Posted November 21, 2012 The example script is a bit "crowded" but you strip it down to a quite short script. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
YoannMorl Posted November 21, 2012 Author Posted November 21, 2012 I've tried some things, but nothing seems to work. I generate my array like that : ; List all the ini files $aIni_List = _FileListToArray(@ScriptDir & "DB", "*.ini", 1) ; Check how many key=value pairs we will get $aIni_Content = IniReadSection(@ScriptDir & "DB" & $aIni_List[1], "INFOS") ; And create a suitably sized array to hold all the data Global $aResults[$aIni_List[0] + 1][$aIni_Content[0][0]] ; Set the title row For $i = 1 To $aIni_Content[0][0] $aResults[0][$i - 1] = $aIni_Content[$i][0] Next ; Now get the values from each file and put them into the array For $i = 1 To $aIni_List[0] $aIni_Content = IniReadSection(@ScriptDir & "DB" & $aIni_List[$i], "INFOS") For $j = 1 To $aIni_Content[0][0] $aResults[$i][$j - 1] = $aIni_Content[$j][1] Next Next ; And show the result _ArrayDisplay($aResults) This is my form : $MainForm = GUICreate("Gestion des Réservations des Ressources- SOGETI/CEA", 609, 594, -1, -1) $fichier = GUICtrlCreateMenu("&Fichier") $Exit = GUICtrlCreateMenuItem("Quitter"&@TAB&"", $fichier) $MenuItem2 = GUICtrlCreateMenu("&Gestion") $MenuItem1 = GUICtrlCreateMenuItem("Ajouter une Ressource"&@TAB&"", $MenuItem2) $MenuItem3 = GUICtrlCreateMenuItem("Supprimer une Ressource"&@TAB&"", $MenuItem2) $MenuItem4 = GUICtrlCreateMenuItem("Export BdD"&@TAB&"", $MenuItem2) $Group1 = GUICtrlCreateGroup("Statistiques", 496, 0, 105, 73) $Label1 = GUICtrlCreateLabel("Libres :", 504, 16, 38, 17) $Label2 = GUICtrlCreateLabel("0", 544, 16, 10, 17) $Label3 = GUICtrlCreateLabel("En Prets :", 504, 32, 50, 17) $Label4 = GUICtrlCreateLabel("0", 560, 32, 10, 17) $Label5 = GUICtrlCreateLabel("En Refontes :", 504, 48, 69, 17) $Label6 = GUICtrlCreateLabel("0", 576, 48, 10, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group2 = GUICtrlCreateGroup("Gestion", 8, 0, 481, 73) $MainResa = GUICtrlCreateButton("Réservation", 16, 16, 83, 49) $MainRetour = GUICtrlCreateButton("Retour", 112, 16, 83, 49) $MainRefonte = GUICtrlCreateButton("Refonte", 208, 16, 83, 49) $Button1 = GUICtrlCreateButton("Button1", 304, 16, 83, 49) $Button2 = GUICtrlCreateButton("Button2", 400, 16, 83, 49) GUICtrlCreateGroup("", -99, -99, 1, 1) $Edit1 = GUICtrlCreateEdit("", 8, 80, 593, 489) GUICtrlSetData(-1, "Edit1") GUISetState(@SW_SHOW) I'd like to replace the "Edit" by the array.
water Posted November 21, 2012 Posted November 21, 2012 This is a stripped down example how to fill a listview with an array and call a sort function when thje suer clicks on the column heading: expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> Global $hListView, $B_DESCENDING, $aArray[7][3] = [["line4", "5", "more_a"],["line5", "4.0 ", "more_c"],["line3", "23", "more_e"],["line2", "0.34560 ", "more_d"],["line1", "1.0 ", "more_b"],["line1", "0.1 ", "more_b"],["line1", "10", "more_b"]] _Main() Func _Main() GUICreate("ListView SimpleSort", 400, 300) $hListView = GUICtrlCreateListView("col1|col2|col3", 2, 2, 394, 268) GUICtrlSendMsg($hListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES) GUICtrlSendMsg($hListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT) _GUICtrlListView_AddArray($hListView, $aArray) _GUICtrlListView_SetColumnWidth($hListView, 0, 75) _GUICtrlListView_SetColumnWidth($hListView, 1, 75) _GUICtrlListView_SetColumnWidth($hListView, 2, 75) GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($hListView)] ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>_Main 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) _GUICtrlListView_SimpleSort($hWndListView, $B_DESCENDING, DllStructGetData($tInfo, "SubItem")) ; No return value EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
YoannMorl Posted November 21, 2012 Author Posted November 21, 2012 (edited) Ok, it works with some adaptation to my code. How i can remove the first line of my array ? I've got name on colum well i don't need the first line. Edited November 21, 2012 by YoannMorl
water Posted November 21, 2012 Posted November 21, 2012 Then you have to fill the ListView yourself. Example: expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> Global $hListView, $B_DESCENDING, $aArray[7][3] = [["line4", "5", "more_a"],["line5", "4.0 ", "more_c"],["line3", "23", "more_e"],["line2", "0.34560 ", "more_d"],["line1", "1.0 ", "more_b"],["line1", "0.1 ", "more_b"],["line1", "10", "more_b"]] _Main() Func _Main() GUICreate("ListView SimpleSort", 400, 300) $hListView = GUICtrlCreateListView("col1|col3", 2, 2, 394, 268) GUICtrlSendMsg($hListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES) GUICtrlSendMsg($hListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT) For $i = 2 To 5 $sEntry = $aArray[$i][0] & "|" & $aArray[$i][2] GUICtrlCreateListViewItem($sEntry, $hListView) Next _GUICtrlListView_SetColumnWidth($hListView, 0, 75) _GUICtrlListView_SetColumnWidth($hListView, 1, 75) _GUICtrlListView_SetColumnWidth($hListView, 2, 75) GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($hListView)] ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>_Main 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) _GUICtrlListView_SimpleSort($hWndListView, $B_DESCENDING, DllStructGetData($tInfo, "SubItem")) ; No return value EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
YoannMorl Posted November 21, 2012 Author Posted November 21, 2012 (edited) This is my script, don't know where is the mistake. The first line doesnt disapear expandcollapse popupFunc _Report() ; List all the ini files $aIni_List = _FileListToArray(@ScriptDir & "DB", "*.ini", 1) ; Check how many key=value pairs we will get $aIni_Content = IniReadSection(@ScriptDir & "DB" & $aIni_List[1], "INFOS") ; And create a suitably sized array to hold all the data Global $aResults[$aIni_List[0] + 1][$aIni_Content[0][0]] ; Set the title row For $i = 1 To $aIni_Content[0][0] $aResults[0][$i - 1] = $aIni_Content[$i][0] Next ; Now get the values from each file and put them into the array For $i = 1 To $aIni_List[0] $aIni_Content = IniReadSection(@ScriptDir & "DB" & $aIni_List[$i], "INFOS") For $j = 1 To $aIni_Content[0][0] $aResults[$i][$j - 1] = $aIni_Content[$j][1] Next Next ; And show the result ;_ArrayDisplay($aResults) Global $hListView, $B_DESCENDING, $aResults, $aArray = $aResults $hListView = GUICtrlCreateListView("INV|TYPE|MARQUE|MODELE|SERIE|ETAT|SD|DU|AU|NOM|PRENOM|CARTE|DEPT|TEL|LOC|MAIL", 8, 80, 593, 250) _GUICtrlListView_SetColumnWidth($hListView, 0, 72) _GUICtrlListView_SetColumnWidth($hListView, 1, 0) _GUICtrlListView_SetColumnWidth($hListView, 2, 0) _GUICtrlListView_SetColumnWidth($hListView, 3, 0) _GUICtrlListView_SetColumnWidth($hListView, 4, 0) _GUICtrlListView_SetColumnWidth($hListView, 5, 72) _GUICtrlListView_SetColumnWidth($hListView, 6, 72) _GUICtrlListView_SetColumnWidth($hListView, 7, 0) _GUICtrlListView_SetColumnWidth($hListView, 8, 72) _GUICtrlListView_SetColumnWidth($hListView, 9, 150) _GUICtrlListView_SetColumnWidth($hListView, 10, 120) _GUICtrlListView_SetColumnWidth($hListView, 11, 0) _GUICtrlListView_SetColumnWidth($hListView, 12, 0) _GUICtrlListView_SetColumnWidth($hListView, 13, 0) _GUICtrlListView_SetColumnWidth($hListView, 14, 0) _GUICtrlListView_SetColumnWidth($hListView, 15, 0) GUICtrlSendMsg($hListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES) GUICtrlSendMsg($hListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT) For $i = 15 To 0 $sEntry = $aArray[$i][0] & "|" & $aArray[$i][2] GUICtrlCreateListViewItem($sEntry, $hListView) Next _GUICtrlListView_AddArray($hListView, $aArray) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($hListView)] EndFunc In fact, my array is loaded from some ini files. The first row contains Key from ini files. I just like to remove this row containing keys because i have already nammed m columns. Edited November 21, 2012 by YoannMorl
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now