Jump to content

Recommended Posts

Posted (edited)

I couldn't find such a function (could be I'm not looking in the right place), but I thought this was useful.

; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlListView_GetContents
; Description ...: A function to captures the contents of a SysListView32 control into an Array
; Syntax.........: _GUICtrlListView_GetContents($hWnd)
; Parameters ....: $hWnd            - A handle to a SysListView32 control.
; Return values .: Success          - An array containing SysListView32 control contents.
;                  Failure          - Returns zero and sets the @error flag:
;                                   |1 - $hWnd Parameter failed IsHwnd type check.
;                                   |2 - If Row or Column count of SysListView32 control equals zero.
; Author ........: Paul Wilson (spudw2k)
; Modified.......: 11/05/2020 (spudw2k)
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _GUICtrlListView_GetContents($hWnd)
    If Not IsHWnd($hWnd) Then Return SetError(1, 0, 0)                              ;Verify input variable is valid Handle

    $iCols = _GUICtrlListView_GetColumnCount($hWnd)                     ;Get SysListView control Column count
    $iRows = _GUICtrlListView_GetItemCount($hWnd)                       ;Get SysListView control Row count
    If $iCols = 0 Or $iRows = 0 Then Return SetError (2, 0, 0)          ;If Column or Row count + 0, then error

    Dim $aListView[$iRows+1][$iCols]        ;Instantiate Array, sized to hold SysListView contents (rows & columns)

    For $iX = 0 to $iCols-1                                                         ;Loop through Columns
        $aListView[0][$iX] = _GUICtrlListView_GetColumn($hWnd,$iX)[5]                   ;Get Column name and set first row of array
    Next                                                                            ;Continue Loop for each Column

    For $iX = 0 to $iRows-1                                                         ;Loop through Rows
        For $iY = 0 To $iCols-1                                                         ;Loop Through Columns
            $aListView[$iX+1][$iY]=_GUICtrlListView_GetItemText($hWnd,$iX,$iY)              ;Get Column value and set Rou# / Col# in array
        Next                                                                            ;Continue Loop for each Column
    Next                                                                            ;Continue Loop through each Row

    Return $aListView       ;Return array containing SysListView contents
EndFunc   ;==>_GUICtrlListView_GetContents

 

Demo

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <Array.au3>

Local $hGUI, $hImage, $hListView
$hGUI = GUICreate("(UDF Created) ListView Create", 400, 300)

$hListView = _GUICtrlListView_Create($hGUI, "", 2, 2, 394, 268)

_GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)
_GUICtrlListView_InsertColumn($hListView, 1, "Column 2", 100)
_GUICtrlListView_InsertColumn($hListView, 2, "Column 3", 100)

_GUICtrlListView_AddItem($hListView, "Row 1: Col 1", 0)
_GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 2", 1)
_GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 3", 2)
_GUICtrlListView_AddItem($hListView, "Row 2: Col 1", 1)
_GUICtrlListView_AddSubItem($hListView, 1, "Row 2: Col 2", 1)
_GUICtrlListView_AddItem($hListView, "Row 3: Col 1", 2)

GUISetState(@SW_SHOW)

$aListViewContents = _GUICtrlListView_GetContents($hListView)
_ArrayDisplay($aListViewContents)

; Loop until the user exits.
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()


Func _GUICtrlListView_GetContents($hWnd)
    If Not IsHWnd($hWnd) Then Return SetError(1, 0, 0)                              ;Verify input variable is valid Handle

    $iCols = _GUICtrlListView_GetColumnCount($hWnd)                     ;Get SysListView control Column count
    $iRows = _GUICtrlListView_GetItemCount($hWnd)                       ;Get SysListView control Row count
    If $iCols = 0 Or $iRows = 0 Then Return SetError (2, 0, 0)          ;If Column or Row count + 0, then error

    Dim $aListView[$iRows+1][$iCols]        ;Instantiate Array, sized to hold SysListView contents (rows & columns)

    For $iX = 0 to $iCols-1                                                         ;Loop through Columns
        $aListView[0][$iX] = _GUICtrlListView_GetColumn($hWnd,$iX)[5]                   ;Get Column name and set first row of array
    Next                                                                            ;Continue Loop for each Column

    For $iX = 0 to $iRows-1                                                         ;Loop through Rows
        For $iY = 0 To $iCols-1                                                         ;Loop Through Columns
            $aListView[$iX+1][$iY]=_GUICtrlListView_GetItemText($hWnd,$iX,$iY)              ;Get Column value and set Rou# / Col# in array
        Next                                                                            ;Continue Loop for each Column
    Next                                                                            ;Continue Loop through each Row

    Return $aListView       ;Return array containing SysListView contents
EndFunc   ;==>_GUICtrlListView_GetContents
Edited by spudw2k
updated function
Posted

Very nice!! I like it.

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

  • 1 month later...
Posted

There is a one problem

if I try to

Retrieve SysListView32 Contents from ListView with 1000 elements

then

I Retrive only that part which is visible on the screen at the moment, all others are not retrived

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
Posted

I check it problem again now on some different machine

hmm..... now I can't repeat that situation.

but now I try on different system, programs..... even AUTOIT version

I think

check this problem again on this same machine ..... environment

but this need time .. to next visit my client

I think it is posible situation in which I change something in program on which was source ListView

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

I modify your Function and create another usefull functions

Func _GUICtrlListView_GetSelectedContents($hWnd)
    $iCol = _GUICtrlListView_GetColumnCount($hWnd)
    If $iCol = 0 Then Return 0
    Dim $arrListView[1][$iCol]
    For $i = 0 To $iCol - 1
        Local $Col = _GUICtrlListView_GetColumn($hWnd, $i)
        $arrListView[0][$i] = $Col[5]
    Next
    $Col = 0
    $iRows = _GUICtrlListView_GetSelectedIndices($hWnd)
    $arr_iRows = StringSplit($iRows, "|")
    For $i = 1 To $arr_iRows[0]
        ReDim $arrListView[UBound($arrListView) + 1][$iCol]
        $arrListView[UBound($arrListView) - 1][0] = _GUICtrlListView_GetItemText($hWnd, $arr_iRows[$i])
        For $j = 1 To $iCol - 1
            $arrListView[UBound($arrListView) - 1][$j] = _GUICtrlListView_GetItemText($hWnd, $arr_iRows[$i], $j)
        Next
    Next
    Return $arrListView
EndFunc   ;==>_GUICtrlListView_GetSelectedContents
Func _GUICtrlListView_GetSelectedContentsFromSomeColumns($hWnd, $sColumnToCheck = "")
    Local $var_to_return = "null"
    $arrToCheck = _GUICtrlListView_GetSelectedContents($hWnd)
    $rows = UBound($arrToCheck)
    $cols = UBound($arrToCheck, 2)
    $aColumnToCheck = StringSplit($sColumnToCheck, "|")
    For $x = 1 To $aColumnToCheck[0]
        For $y = 0 To $cols - 1
            If $aColumnToCheck[$x] = $arrToCheck[0][$y] Then
                If $var_to_return = "null" Then
                    $var_to_return = String($y)
                Else
                    $var_to_return &= "|" & String($y)
                EndIf
            EndIf
        Next
    Next
    If $var_to_return = "" Then
        Return 1 ;do not found anything
    Else
        $aFoundColumns = StringSplit($var_to_return, "|")
        Dim $aToReturn[$rows][$aFoundColumns[0]]
        For $a = 1 To $aFoundColumns[0]
            For $b = 0 To $rows - 1
                $aToReturn[$b][$a - 1] = $arrToCheck[$b][$aFoundColumns[$a]]
            Next
        Next
        Return $aToReturn
    EndIf
EndFunc   ;==>_GUICtrlListView_GetSelectedContentsFromSomeColumns

usage:

_GUICtrlListView_GetSelectedContentsFromSomeColumns($hWnd, "ColName3|ColName1|ColName5")

Returned array has a new column order

first is ColName3 next ColName1 and Last ColName5

Edited by mlipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

I a discover another problem

In Scite

when I GO SCRIPT then no one items are retrived

but

when I COMPILE SCRIPT then all works fine

It's possible I have wrong version or config.

Can anybody help me ?

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

From the help-file for ControlListView():

"Some commands may fail when using a 32-bit AutoIt process to read from a 64-bit process. Likewise commands may fail when using a 64-bit AutoIt process to read from a 32-bit process."

So accessing ListViews (and TreeViews too) the scripts needs to run / be compiled for the right @OSArch. See ICU in my signature how melba23 and I enforced the usage of the right architecture there.

  • 10 years later...
Posted (edited)

Hello , @spudw2k

I know its an old thread , but unable to find the solution.
I am using the code , exactly as it is.  x86.

Facing the same issue : Retrieving only visible data.
It retrieves all the rows , but only the live updated data for the rows which are currently visible.
For the bottom rows , it fetches stale data.

If I merely scroll down ,even with the program already running it starts fetching the
bottom rows correct live updated data.
 

Func FetchPrice($optiontype,$strikeprice)
$arrBankNiftyMW = _GUICtrlListView_GetContents($handleBankNiftyMarketWatchList)
For $i = 0 To UBound($arrBankNiftyMW)-1 Step 1
If  $arrBankNiftyMW[$i][3] = $optiontype And $arrBankNiftyMW[$i][2] = $strikeprice Then
Return $arrBankNiftyMW[$i][4]
EndIf
Next
EndFunc


If ( FetchPrice("CE",$activeCEStrike) > 200 ) Then

FileWrite($hFileOpen,$activeCEStrike)
FileWrite($hFileOpen,",")
FileWrite($hFileOpen,FetchPrice("CE",$activeCEStrike) )

 

 

Please do assist in resolving this. Let me know how I can help you in replicating the issue or any other code / config trials at my end.

Thanks

 

Screenshot (14).png

Edited by adityaparakh
Inserted Screenshot.
Posted

Interesting.  Without having the listview to test with I can only speculate what the issue is.  My suspicion is that the list view doesn't actually contain the "fresh' data either, until the relevant row (item) is in view so as to make the UI "more efficient".  There may be a way to send a redraw message to the list view control, but there may be (is likely) some underlying function / code in the app that actually updates the data.

Maybe someone smarter then me can help you hook and/or send the redraw message and you can at least do some analysis to see if that is enough to get the data to show up.

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
  • Recently Browsing   0 members

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