Jump to content

Read data from a ListView without selecting ?


ptrex
 Share

Recommended Posts

Is it possible to read the data in the ListView to a variable or Array.

Without having to select the items by hand in the ListView.

Because that' s what all the current function like _GUICtrlListViewGetItemTextArray demand, is a manual selection.

Link to comment
Share on other sites

you mean something like?

#include <GuiConstants.au3>
#include <GuiListView.au3>

Opt ('MustDeclareVars', 1)
Dim $listview, $Btn_Get, $Btn_Exit, $msg, $Status, $ret
GUICreate("ListView Get Item Text", 392, 322)

$listview = GUICtrlCreateListView("col1|col2|col3", 40, 30, 310, 149)
GUICtrlCreateListViewItem("line1|data1|more1", $listview)
GUICtrlCreateListViewItem("line2|data2|more2", $listview)
GUICtrlCreateListViewItem("line3|data3|more3", $listview)
GUICtrlCreateListViewItem("line4|data4|more4", $listview)
GUICtrlCreateListViewItem("line5|data5|more5", $listview)
$Btn_Get = GUICtrlCreateButton("Get data", 75, 200, 90, 40)
$Btn_Exit = GUICtrlCreateButton("Exit", 300, 260, 70, 30)
$Status = GUICtrlCreateLabel("", 0, 302, 392, 20, BitOR($SS_SUNKEN, $SS_CENTER))

GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $Btn_Exit
            ExitLoop
        Case $msg = $Btn_Get
            GUICtrlSetData($Status, "")
            Local $a_list, $x
            For $x = 0 To _GUICtrlListViewGetItemCount($listview) - 1
                If IsArray($a_list) Then
                    ReDim $a_list[UBound($a_list) + 1]
                Else
                    Dim $a_list[1]
                EndIf
                $a_list[UBound($a_list) - 1] = _GUICtrlListViewGetItemText ($listview, $x)
            Next
            For $x = 0 To UBound($a_list) - 1
                MsgBox(0,"a_list[" & $x & "]",$a_list[$x])
            Next
    EndSelect
WEnd
Exit
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Hihaaaaa, that' s it !!

This is a good suggestion for a standard UDF.

Because I thought that the functions like _GUICtrlListViewGetItemText would read all or part, of the data from the ListView. As it is said in the Helpfile text

Found out later on that it only read the data, after manually selecting it.

So you solution is missing as a standard function. Maybe usefull for many others.

May come handy when people working with listView, want to read the data for what ever reason, and use it later on.

I will incorporate your solution in the SQL solution, for exporting data from a ListView to a file or Excel.

Thanks a lot !!

Link to comment
Share on other sites

@ptrex

Because I thought that the functions like _GUICtrlListViewGetItemText would read all or part, of the data from the ListView. As it is said in the Helpfile text

Found out later on that it only read the data, after manually selecting it

You were right on the first part. _GUICtrlListViewGetItemText() dosen't need any ListView items to be selected. The script by gafrost is not selecting any ListView items.

The second part is not correct.

Link to comment
Share on other sites

now that i had some coffee and am awake, didn't need as many lines of code to get the data

Local $a_list[_GUICtrlListViewGetItemCount($listview)], $x
            For $x = 0 To _GUICtrlListViewGetItemCount($listview) - 1
                $a_list[$x] = _GUICtrlListViewGetItemText ($listview, $x)
            Next
            For $x = 0 To UBound($a_list) - 1
                MsgBox(0,"a_list[" & $x & "]",$a_list[$x])
            Next
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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...