Jump to content

Displaying a table/array in a GUI with sort function and nammed cols


 Share

Recommended Posts

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.

Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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:

#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 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

Then you have to fill the ListView yourself. Example:

#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 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

This is my script, don't know where is the mistake. The first line doesnt disapear

Func _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 by YoannMorl
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...