Jump to content

Recommended Posts

Posted (edited)

Hi all :)
The function _GUICtrlListView_SetItemSelected() didn't work in a script I'm working on.
So I came back to the example found in the help file (which works), added 1 line to it and could reproduce the issue :

23128178_999a-selected.png.019b911fc5a2b9cc1820bdb1351d8a97.png

334434776_999b-unselected.png.945b70029dd94e54b8731473b05cb6aa.png

As you can see in the 2 pics above, depending on where you exactly insert the GUICtrlCreateButton() line, then _GUICtrlListView_SetItemSelected() will select (or not) item 2 in the listview (though the function returns True in both cases). Here is the complete script, where item 2 appears unselected :

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

Example()

Func Example()
    Local $idListview

    GUICreate("ListView Set Item Selected", 300, 110)
    Local $idButton = GUICtrlCreateButton("Button", 175, 50, 75, 20)
    $idListview = GUICtrlCreateListView("", 4, 4, 125, 100)
    GUISetState(@SW_SHOW)

    ; Add columns
    _GUICtrlListView_AddColumn($idListview, "Items", 100)

    ; Add items
    _GUICtrlListView_AddItem($idListview, "Item 1")
    _GUICtrlListView_AddItem($idListview, "Item 2")
    _GUICtrlListView_AddItem($idListview, "Item 3")

    ; Select item 2
    _GUICtrlListView_SetItemSelected($idListview, 1)
    ; MsgBox($MB_SYSTEMMODAL, "Information", "Item 2 Selected: " & _
    ;   _GUICtrlListView_GetItemSelected($idListview, 1))

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

Maybe this could help another user facing the same problem.

Edit: found why. In the 2nd pic, Button got the focus, so focusing on ListView before calling the function seems to solve all cases :

; Select item 2
GUICtrlSetState($idListview, $GUI_FOCUS)
_GUICtrlListView_SetItemSelected($idListview, 1)

 

Edited by pixelsearch
found why

"I think you are searching a bug where there is no bug... don't listen to bad advice."

Posted (edited)

Nothing wrong here.

ListView is "not focused" so windows change color of selected LV Item.

Try to use     ControlFocus() function like in this following example:

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

Example()

Func Example()


    GUICreate("ListView Set Item Selected", 300, 110)
    Local $idButton = GUICtrlCreateButton("Button", 175, 50, 75, 20)
    Local $idListview = GUICtrlCreateListView("", 4, 4, 125, 100)
    #forceref $idButton
    GUISetState(@SW_SHOW)

    ; Add columns
    _GUICtrlListView_AddColumn($idListview, "Items", 100)

    ; Add items
    _GUICtrlListView_AddItem($idListview, "Item 1")
    _GUICtrlListView_AddItem($idListview, "Item 2")
    _GUICtrlListView_AddItem($idListview, "Item 3")

    ; Select item 2
    _GUICtrlListView_SetItemSelected($idListview, 1)
    ControlFocus('ListView Set Item Selected','',$idListview)

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

 

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

Thanks mLipok :)
I used this line a few min ago and it worked fine :

GUICtrlSetState($idListview, $GUI_FOCUS)

I'll remember to give the focus to ListView as soon as a related function doesn't seem to work in the script

"I think you are searching a bug where there is no bug... don't listen to bad advice."

  • Moderators
Posted

Moved to the appropriate forum.

Moderation Team

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted (edited)

Can't believe I got another button question the same day.
This one is related to a good script of Melba23's, found here. His script allows to select any subitem individually in a listview (using the mouse)

641665710_998a-withbutton.png.4ac981668dedbfb2fbfe798b37437f27.png

Pic #1 above : see how the cell is nicely selected when there is a button in the Gui ?

855124671_998b2-withoutbutton.png.49b446178cc659201fac78188ef8c57d.png
Pic #2 : without the button in the Gui, a kind of "row selection shade" appears (on a white background)
If anyone got an explanation, thanks for sharing it.

To run Melba23's script, a file named "edit-zoom_step_av_value.csv" is required and found at the very end of the post preceding Melba's

Edited by pixelsearch

"I think you are searching a bug where there is no bug... don't listen to bad advice."

Posted (edited)

Just add

_GUICtrlListView_SetCallBackMask( $cListview, 4 ) ; Disable state information about focused item

immediately after creation of the listview. This command disables the dotted focus rectangle around the listview item which has the input focus. Untested. But it should work.

Edited by LarsJ
Posted

Thx LarsJ :thumbsup:
Your line of code did it, in Melba's script (without the button) and also in a little script I'm working on, learning how to select subitems not only with clicks but with the 4 direction keys, Enter key being managed in ListView via Yashied's Wsp.dll found here... which made you react there

We're lucky to have you on this site.

 

 

 

"I think you are searching a bug where there is no bug... don't listen to bad advice."

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