Sign in to follow this  
Followers 0
pl123

Help with ListView Items

4 posts in this topic

I'm trying to make the total amount of RAM, pagefile, and virtual show in a ListView, so I used MemGetStats (), and setting the values for the arrays [1],[3],[5]:

$MemStats = MemGetStats ()
$MemStats[1] = $TotalPhysRAM
$MemStats[3] = $TotalPagefile
$MemStats[5] = $TotalVirtual

Then, I'm adding them to the ListView:

Global Const $LeftBorder = 10 ; Left 'margin' size

$MainWindow = GUICreate ($GUITitle, 400, 450)
GUISetState (@SW_SHOW, $MainWindow)
WinSetOnTop ($GUITitle, "", 1)
GUICtrlCreateTab (5, 5, 390, 25)

---- omitted ----

$Tab[1] = GUICtrlCreateTabItem ("Computer Specs")
GUICtrlCreateLabel ("******************", $LeftBorder, 35)
GUICtrlCreateLabel ("******************", $LeftBorder, 50)
GUICtrlCreateLabel ("————————————————————————————————————————————————————————————————", $LeftBorder, 62) ; divider line

$MemStats = MemGetStats ()
$MemStats[1] = $TotalPhysRAM
$MemStats[3] = $TotalPagefile
$MemStats[5] = $TotalVirtual

$SpecsList = GUICtrlCreateListView ("****************|Value", $LeftBorder, 75, 380, 300)
GUICtrlCreateListViewItem ("Total Physical RAM|" & $TotalPhysRAM & "", $SpecsList)
GUICtrlCreateListViewItem ("Total Pagefile|" & $TotalPagefile & "", $SpecsList)
GUICtrlCreateListViewItem ("Total Virtual Memory|" & $TotalVirtual & "", $SpecsList)

However, the three items do not show up on the list view thingy. Is there anything wrong? Thanks! =)

Share this post


Link to post
Share on other sites



pl123,

Is there anything wrong?

I am afraid so! :D

MemGetStats returns an array already filled with the data. By using this code:

$MemStats = MemGetStats ()
$MemStats[1] = $TotalPhysRAM
$MemStats[3] = $TotalPagefile
$MemStats[5] = $TotalVirtual

you are replacing the data you have obtained with the contents of those 3 variables - which as you have not declared them is an empty string. Hence nothing to display in the ListView. :(

What you need to do is reverse the order of the assignation statements like this:

$MemStats = MemGetStats ()
$TotalPhysRAM = $MemStats[1]
$TotalPagefile = $MemStats[3]
$TotalVirtual = $MemStats[5]

and you will find that your ListView magically fills with the data. :graduated:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Hallo)

pl123 Personally i like Listview :graduated:

Here is my code:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

Global $avaray

$Form1 = GUICreate("Test Programm", 510, 255, 389, 325)
$ListView1 = GUICtrlCreateListView("Memory Load (%)" &  "|" &"Total physical RAM" &  "|" &"Available physical RAM" &  "|", 80, 40, 361, 137)
$Button1 = GUICtrlCreateButton("Re Scan", 96, 208, 89, 25, $WS_GROUP)
$Button3 = GUICtrlCreateButton("Delete All Items", 344, 208, 89, 25, $WS_GROUP)


$hcontextmenu=GUICtrlCreateContextMenu($ListView1)
$contextmenu_item1=GUICtrlCreateMenuItem("Get Memory Load  in (%)",$hcontextmenu)
GUICtrlCreateMenuItem("",$hcontextmenu)
$contextmenu_item2=GUICtrlCreateMenuItem("Get Total physical RAM",$hcontextmenu)
GUICtrlCreateMenuItem("",$hcontextmenu)
$contextmenu_item3=GUICtrlCreateMenuItem("Get Available physical RAM",$hcontextmenu)
GUICtrlCreateMenuItem("",$hcontextmenu)
$contextmenu_item4_get_all=GUICtrlCreateMenuItem("Get All in One :P",$hcontextmenu)
GUISetState(@SW_SHOW)



_getmem()





While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1;Rescan Mem and Populate it To Listview
        $avaray=""
           _GUICtrlListView_DeleteAllItems($ListView1)
            _getmem()
        Case $Button3
             _GUICtrlListView_DeleteAllItems($ListView1)
             $emptymsg="Listview Emptied!"
             $asnwer=MsgBox(65,$emptymsg,$emptymsg & "Would you like Rescan Mem and Polulate Listview?",15)
             If $asnwer="1" Then
                 _getmem()
                 EndIf




         Case $contextmenu_item1
             $i="0"
             MsgBox(64,"",_GUICtrlListView_GetItemText(GUICtrlGetHandle($ListView1),_GUICtrlListView_GetSelectedIndices($ListView1),$i))
         Case $contextmenu_item2
             $i="1"
             MsgBox(64,"",_GUICtrlListView_GetItemText(GUICtrlGetHandle($ListView1),_GUICtrlListView_GetSelectedIndices($ListView1),$i))
         Case $contextmenu_item3
             $i="2"

             MsgBox(64,"",_GUICtrlListView_GetItemText(GUICtrlGetHandle($ListView1),_GUICtrlListView_GetSelectedIndices($ListView1),$i))

            Case $contextmenu_item4_get_all
        MsgBox(64,"","Memory Load (%) " &_GUICtrlListView_GetItemText(GUICtrlGetHandle($ListView1),_GUICtrlListView_GetSelectedIndices($ListView1),0)  & @CRLF & _
         "Total physical RAM " &   _GUICtrlListView_GetItemText(GUICtrlGetHandle($ListView1),_GUICtrlListView_GetSelectedIndices($ListView1),1) & @CRLF & _
          "Available physical RAM " & _GUICtrlListView_GetItemText(GUICtrlGetHandle($ListView1),_GUICtrlListView_GetSelectedIndices($ListView1),2))


;

    EndSwitch
WEnd


Func _getmem()


    $avaray=MemGetStats()
    _populate()

    EndFunc ;==> _getmem()




Func _populate()
    GUICtrlCreateListViewItem($avaray[0] & "|" & $avaray[1] & "|" & $avaray[2],$ListView1)
    EndFunc ; ==>_populate()

[size="5"] [/size]

Share this post


Link to post
Share on other sites

Ok, I got it fixed now. Thanks both of you for your help! =)

Share this post


Link to post
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
Sign in to follow this  
Followers 0