Sign in to follow this  
Followers 0
Ace08

GUICtrlRead($listview) = 4?

7 posts in this topic

#1 ·  Posted (edited)

uhm guys just want to know why is this happening when running the script with a list box i run the code GUICtrlRead($listview) that gives me a number of 0 that i understand since i still havn't choose one item in the list box but when i choose the 1st item it gives me a value of 4 instead of 1?

oh and another thing is there a way to determine a controlid if i didn't assign it into a variable? say like this GUICtrlCreateListViewItem("item1|item2|item3", $listview) would the script know what items i am specifying?

Edited by Ace08

Work smarter not harder.My First Posted Script: DataBase

Share this post


Link to post
Share on other sites



Try it this way.. GUICtrlRead(GUICtrlRead($listview)).


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

thanks somdcomputerguy for the reply i did that one too but that one gives the value of the listitem itself, what i would like to know is if i can get the controlid itself because what i would like to do is get the value in a listbox edit it then return it to the listbox.... would that be possible?


Work smarter not harder.My First Posted Script: DataBase

Share this post


Link to post
Share on other sites

Ace08,

Firstly, you speak of List boxes, but use $listview as an identifier - List and ListView controls are very different beasts. As your problem seems to match the bahaviour of a ListView, I will assume that is what you mean. ;)

From the Help file page for GUICtrlRead:

Return value:

ListView - Control identifier (controlID) of the selected ListViewItem. 0 means no item is selected

Now run this script and look at the values you get as ControlIDs:

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$hListView = GUICtrlCreateListView("Title", 10, 10, 480, 300)
For $i = 1 To 4
    $iControlID = GUICtrlCreateListViewItem($i, $hListView)
    ConsoleWrite("ListView item " & $i & " has a ControlID of " & $iControlID & @CRLF)
Next

$hButton = GUICtrlCreateButton("Read", 10, 350, 80, 30)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            ConsoleWrite(GUICtrlRead($hListView) & @CRLF)
    EndSwitch
WEnd

You will see that the ControlID values are returned when you read the ListView with the button - just like the help file says. :shocked:

If you want to change the value of the item, just use GUICtrlSetData like this: ;)

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$hListView = GUICtrlCreateListView("Title      ", 10, 10, 480, 300)
For $i = 1 To 4
    GUICtrlCreateListViewItem($i, $hListView)
Next

$hButton = GUICtrlCreateButton("Amend", 10, 350, 80, 30)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            GUICtrlSetData(GUICtrlRead($hListView), "New data")
    EndSwitch
WEnd

All clear? :)

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

#5 ·  Posted (edited)

Wow, thanks a lot Melba23 your example was the one im looking for ;)

so i can use this GUICtrlRead($hListView)as a controlid if i didn't placed it in a variable i was thinking before that it only returns the line number where the list items are placed :)

ListView - Control identifier (controlID) of the selected ListViewItem. 0 means no item is selected

Yes that is but when i choose the 1st item it gives me a value of 4 why? does the value 1~3 have another meaning in a listview? im still confused about this one. Edited by Ace08

Work smarter not harder.My First Posted Script: DataBase

Share this post


Link to post
Share on other sites

Ace08,

A ControlID is actually the index of the control in AutoIt's internal array where all the controls created with the built-in commands are listed. Only those commands are listed here - if you use the UDFs to create controls, you will see that they return normal Windows handles, not ControlIDs. ;)

The first control you create always has the ControlID of 3 as you can see by adding this line to the script above: ;)

$hListView = GUICtrlCreateListView("Title", 10, 10, 480, 300)
ConsoleWrite("ListView ControlID: " & $hListView & @CRLF) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

I assume that the first few elements of the internal array are taken up with items in the ever-present, but hidden, AutoIt window so that the first available element is #3.

Any more questions :)

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

Hi Melba23 you're up late ;)

Thanks for the info so that means it returns the controls you made in a gui like for example in your code i changed GUICtrlRead($hListView) to GUICtrlRead(8) and it gave me the value of a button since the button control was created 8th

This one is very usefull for me thanks again because i want to read the entire contents of the listview so i wanted to know which control i will start and stop ;)

So far that would be my last question(until i get a new one :)) Thanks for th help


Work smarter not harder.My First Posted Script: DataBase

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