Jump to content
Sign in to follow this  
Zaxon

GUICtrlRead doesn't work on a listview

Recommended Posts

OK. Quiz time. Let's create two windows and place a listview in each. Select an item from the list in the SECOND window. What do you get?

#include <GuiConstants.au3>

; open window 1
$mainh = GUICreate("main window", 665, 450, -1, -1)
$main_list=GUICtrlCreateListView("Window One",0,0,300,450)
GUICtrlCreateListViewItem("hello there",$main_list)
GUISetState()

; open window 2
$viewlogh = GUICreate("View Log", 300, 450, -1, -1)
$log_list=GUICtrlCreateListView("Window Two",0,0,300,450)
GUICtrlCreateListViewItem("I'm over here",$log_list)
guisetstate()

guiswitch($viewlogh); switch to window 2 just to make sure
sleep(3000)
msgbox(0,"",GUICtrlRead(GUICtrlRead($log_list)))

* Run the code above

* Select the item in the second window - you've got 3 seconds

* What item does it say is selected?

Bzzzst! It's returning a result from window 1, even though it clearly is supposed to be interrogating $log_list (i.e. the listview in window 2).

Anyone can help here?

Share this post


Link to post
Share on other sites

Try this:

MsgBox(0,"",GUICtrlRead(GUICtrlRead($log_list)))

<{POST_SNAPBACK}>

Yes, that's an exact quote from my code posted above. Did you want to add something?

Share this post


Link to post
Share on other sites

Why not use just one window?

For Example:

#include <GuiConstants.au3>

; open window 1
$mainh = GUICreate("main window", 665, 450, -1, -1)
$main_list=GUICtrlCreateListView("Window One",0,0,300,450)
GUICtrlCreateListViewItem("hello there",$main_list)
$log_list=GUICtrlCreateListView("Window Two",305,0,300,450)
GUICtrlCreateListViewItem("I'm over here",$log_list)
GUISetState()


sleep(3000)
msgbox(0,"",GUICtrlRead(GUICtrlRead($log_list)))
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.

 

Share this post


Link to post
Share on other sites

Why not use just one window?

<{POST_SNAPBACK}>

This is a part of a complex application, with various windows doing many different things. Because of the fault I found, I extracted the relevant code, stripped it right down so only the essential lines remain, and renamed everything to serve as a simple, clear example of the fault.

This isn't a simple query about how to display two listviews.

Share this post


Link to post
Share on other sites

oups  :D

Had the same problem, and that was MY solution, didn't look trough your code that much...

<{POST_SNAPBACK}>

hehe. Back to readers ed. for you :)

Thanks anyway.

Share this post


Link to post
Share on other sites

Not a fix, this shows what is happening.

Both return the same value, even though both controlids are unique

click the item in each list and see the results.

#include <GuiConstants.au3>

; open window 1
$mainh = GUICreate("main window", 665, 450, -1, -1, -1, $WS_EX_OVERLAPPEDWINDOW)
;~ GUISetState(@SW_SHOW,$mainh)
$mainlh = GUICreate("main window", 300, 450, 0, -1, -1, -1,$mainh)
$main_list=GUICtrlCreateListView("Window One",0,0,300,450)
GUICtrlCreateListViewItem("hello there",$main_list)
GUISetState(@SW_SHOW,$mainlh)


; open window 2
$viewlogh = GUICreate("View Log", 300, 450, 305,-1, -1, -1, $mainh)
$log_list=GUICtrlCreateListView("Window Two",0,0,300,450)
GUICtrlCreateListViewItem("I'm over here",$log_list)
GUISetState(@SW_SHOW,$viewlogh)
Sleep(3000)
;~ MsgBox(0,"",GUICtrlRead(GUICtrlRead($log_list))
MsgBox(0,"",$main_list & @CRLF & GUICtrlRead($main_list) & @CRLF & $log_list & @CRLF & GUICtrlRead($log_list))

SciTE for AutoItDirections for Submitting Standard UDFs

 

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

 

Share this post


Link to post
Share on other sites

Correct, but that was what I was pointing out, now

try replacing the 4 in each listview with the following and see what the result is.

GUICtrlCreateListViewItem("hello there",$main_list)

GUICtrlCreateListViewItem("I'm over here",$log_list)

MsgBox(0,"",GUICtrlRead(GUICtrlRead($log_list)))

and see what is returned.

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.

 

Share this post


Link to post
Share on other sites

Worked on the example, but then when I tried it on a script I've been working

on It didn't, the number returned was different therefore the following works so

you don't have to know what the control is returning

$str1 = ControlListView ( $mainlh, "", $main_list, "GetText", ControlListView ( $mainlh, "", $main_list, "GetSelected"), 0 )
$str2 = ControlListView ( $viewlogh, "", $log_list, "GetText", ControlListView ( $viewlogh, "", $log_list, "GetSelected"), 0 )

SciTE for AutoItDirections for Submitting Standard UDFs

 

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

 

Share this post


Link to post
Share on other sites

oh... i see... that is a scary example... specially for noobs...

I imagine that in order to get the GUICtrlRead to work, you will need to be able to detect the listview that is current and pass that to GUISwitch()... yikes... I need to stop thinkning about this... find a happy place... find a happy place...

Lar.

<{POST_SNAPBACK}>

Actually, the "GUICtrlRead(GUICtrlRead($log_list))" format is extremely commonly used in all sorts of example scripts on this site. And in reality, considering my original script:

1) Guiswitched to the correct window

2) Addressed the $log_list listview by name

...the fact that it doesn't return the correct value has to be a bug in the way listviews are currently implemented, me thinks.

But putting that aside, the original script on which my sample script was based does use ControlListView AND GUICtrlRead in different places. The reason being is that GUICtrlRead returns the entire line, not just one column.

Consider the following slightly modified script:

#include <GuiConstants.au3>

; open window 1
$mainh = GUICreate("main window", 300, 450, 0, -1)
$main_list=GUICtrlCreateListView("Window One|color",0,0,300,450)
GUICtrlCreateListViewItem("hello there|green",$main_list)
GUISetState()

; open window 2
$viewlogh = GUICreate("View Log", 300, 450, -1, -1)
$log_list=GUICtrlCreateListView("Window Two|color",0,0,300,450)
GUICtrlCreateListViewItem("I'm over here|blue",$log_list)
guisetstate()

sleep(3000)

$str1 = ControlListView ( $mainh, "", $main_list, "GetText", GUICtrlRead($main_list) - 4, 0 )
$str2 = ControlListView ( $viewlogh, "", $log_list, "GetText", GUICtrlRead($log_list) - 4,0 )

MsgBox(0,"",$str1 & @CRLF & $str2)

The desired outcome is: I'm over here|blue

Now short of using something like ControlListView ( $viewlogh, "", $log_list, "GetText", GUICtrlRead($log_list) - 4,0 ) & ControlListView ( $viewlogh, "", $log_list, "GetText", GUICtrlRead($log_list) - 4,1 ) & ControlListView ( $viewlogh, "", $log_list, "GetText", GUICtrlRead($log_list) - 4,3 ) & ControlListView ( $viewlogh, "", $log_list, "GetText", GUICtrlRead($log_list) - 4,... ) [my original scripts has more than just two columns] which looks way scarier than the original (but malfunctioning GUICtrlRead(GUICtrlRead($log_list))), is there a simple way of using ControlListView and returning the whole line?

Share this post


Link to post
Share on other sites

I would create a UDF such as the example below.

Give it a try with your example, hope this helps you.

MsgBox(0,"",_ReturnLVSelectedText($main_list,$mainlh,""))


Func _ReturnLVSelectedText($lv, $WindowTitle, $WindowText="")
    Local $X,$count,$str
    if(ControlListView ( $WindowTitle, $WindowText, $lv, "GetSelectedCount")) Then
        $count = ControlListView ( $WindowTitle, $WindowText, $lv, "GetSubItemCount")
    
        For $X=0 To $count - 1 Step 1
            If($str) Then
                $str = $str & "|" & ControlListView ( $WindowTitle, $WindowText, $lv, "GetText", ControlListView ( $WindowTitle, $WindowText, $lv, "GetSelected"), $X )
            Else
                $str = ControlListView ( $WindowTitle, $WindowText, $lv, "GetText", ControlListView ( $WindowTitle, $WindowText, $lv, "GetSelected"), $X )
            EndIf
        Next
    EndIf
    Return $str
EndFunc
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.

 

Share this post


Link to post
Share on other sites

To Every body in this thread :

IT IS A BUG :D:D I will upload a correction in the next 3.1.0+ (15I)

stay tune

will be uploaded in the next couple of hours :)

Share this post


Link to post
Share on other sites

Can't use beta's where I work

So let's take what the function a step further

1st call, no subitem passed in, returns all subitems

2nd call, subitem passed in, only returns the value of that subitem

MsgBox(0,"",_ReturnLVSelectedText($main_list,$mainlh))
MsgBox(0,"",_ReturnLVSelectedText($main_list,$mainlh,"",0))

Func _ReturnLVSelectedText($lv, $WindowTitle, $WindowText="",$SubItem=-1)
    Local $X,$count,$str
    $count = ControlListView ( $WindowTitle, $WindowText, $lv, "GetSubItemCount")
    if(ControlListView ( $WindowTitle, $WindowText, $lv, "GetSelectedCount")) Then
        If($SubItem == -1) Then; return all the subitems in the item selected
        
            For $X=0 To $count - 1 Step 1
                If($str) Then
                    $str = $str & "|" & ControlListView ( $WindowTitle, $WindowText, $lv, "GetText", ControlListView ( $WindowTitle, $WindowText, $lv, "GetSelected"), $X )
                Else
                    $str = ControlListView ( $WindowTitle, $WindowText, $lv, "GetText", ControlListView ( $WindowTitle, $WindowText, $lv, "GetSelected"), $X )
                EndIf
            Next
            Return $str
        ElseIf($SubItem < $count) Then); return the subitem in the item selected
            Return ControlListView ( $WindowTitle, $WindowText, $lv, "GetText", ControlListView ( $WindowTitle, $WindowText, $lv, "GetSelected"), $SubItem )
        Else
        ; set an error, subitem is out of range
            SetError( -1 )
            Return @error
        EndIf
    Else
    ; set an error, no item selected
        SetError( -2 )
        Return @error
    EndIf
EndFunc

SciTE for AutoItDirections for Submitting Standard UDFs

 

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

 

Share this post


Link to post
Share on other sites

Can't use beta's where I work

So let's take what the function a step further

1st call, no subitem passed in, returns all subitems

2nd call, subitem passed in, only returns the value of that subitem

MsgBox(0,"",_ReturnLVSelectedText($main_list,$mainlh))
MsgBox(0,"",_ReturnLVSelectedText($main_list,$mainlh,"",0))

Func _ReturnLVSelectedText($lv, $WindowTitle, $WindowText="",$SubItem=-1)
    Local $X,$count,$str
    $count = ControlListView ( $WindowTitle, $WindowText, $lv, "GetSubItemCount")
    if(ControlListView ( $WindowTitle, $WindowText, $lv, "GetSelectedCount")) Then
        If($SubItem == -1) Then; return all the subitems in the item selected
        
            For $X=0 To $count - 1 Step 1
                If($str) Then
                    $str = $str & "|" & ControlListView ( $WindowTitle, $WindowText, $lv, "GetText", ControlListView ( $WindowTitle, $WindowText, $lv, "GetSelected"), $X )
                Else
                    $str = ControlListView ( $WindowTitle, $WindowText, $lv, "GetText", ControlListView ( $WindowTitle, $WindowText, $lv, "GetSelected"), $X )
                EndIf
            Next
            Return $str
        ElseIf($SubItem < $count) Then); return the subitem in the item selected
            Return ControlListView ( $WindowTitle, $WindowText, $lv, "GetText", ControlListView ( $WindowTitle, $WindowText, $lv, "GetSelected"), $SubItem )
        Else
        ; set an error, subitem is out of range
            SetError( -1 )
            Return @error
        EndIf
    Else
    ; set an error, no item selected
        SetError( -2 )
        Return @error
    EndIf
EndFunc

<{POST_SNAPBACK}>

I can understand you cannot work with a beta.

But to go aroud the bug you need to use only one GUI by script or to have the GUI creating the GUICtrlListView in the first created window.

Otherwise just do what you can with other AutoIt Function

I am sorry for the BUG in the standard release 3.1.0 :)

Share this post


Link to post
Share on other sites

To Every body in this thread :

IT IS A BUG  :D  :D I will upload a correction in the next 3.1.0+ (15I)

stay tune

will be uploaded in the next couple of hours :)

<{POST_SNAPBACK}>

Thanks you jpm. Everyone is pretending that it doesn't work because you shouldn't be doing it this way, and God is punishing you.

gafrost, I'm in a similar situation, in that my app is reliant on Traymenu, so I can only use versions that have that added in.

I've made changes based on your suggestion of piecing the columns together, and it's working fine.

Share this post


Link to post
Share on other sites

Thanks you jpm.  Everyone is pretending that it doesn't work because you shouldn't be doing it this way, and God is punishing you.

gafrost, I'm in a similar situation, in that my app is reliant on Traymenu, so I can only use versions that have that added in.

I've made changes based on your suggestion of piecing the columns together, and it's working fine.

<{POST_SNAPBACK}>

You welcome :)

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...