Sreekanth Posted February 23, 2011 Posted February 23, 2011 Hi, I am new to AutoIt, I have a standalone GUI application containing a ListBox which which displays files in a directory at run time, I am able to get total count of items in the list box but not able to get individual item text. Please help on this. Below is the code written ; Create a handle for list box $hListBoxHandle = ControlGetHandle("", "", "ListBox3") ; Get Items count in the list box $ItemsCount= _GUICtrlListBox_GetCount($hListBoxHandle ) MsgBox(0,"UI Listbox Items count",$ItemsCount) ; Loop through the no. of items in the listbox and display the item text For $i = 0 To $ItemsCount Step 1 MsgBox(0,"Item Text", _GUICtrlListBox_GetText($hListBoxHandle , $i) Next AutoIt window Info of the control is attached.
wakillon Posted February 23, 2011 Posted February 23, 2011 Welcolme to the forums ! Have you try _GUICtrlListBox_GetSelItemsText for retrieves the text of selected items ? AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts
Sreekanth Posted February 23, 2011 Author Posted February 23, 2011 The ListBox items are not selectable, items will be added/updated at run time too. User can only scroll up/down to view items added.
wakillon Posted February 23, 2011 Posted February 23, 2011 The ListBox items are not selectable, items will be added/updated at run time too. User can only scroll up/down to view items added.Ok !So, why not use a ListView instead of ListBox ?you could get text by _GUICtrlListView_GetItemText... AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts
Sreekanth Posted February 23, 2011 Author Posted February 23, 2011 This is not a list-view control, autoit window info saying it is listbox control - CLASS: ListBox. How can I use ListView? Even I tried using ListView control, now even item count is showing 0 and item text is displayed nothing during the loop. ; Create a handle for listview $hListBoxHandle = ControlGetHandle("", "", "ListBox3") ; Get Items count in the list view $ItemsCount= _GUICtrlListView_GetItemCount($hListBoxHandle ) MsgBox(0,"UI Listbox Items count",$ItemsCount) ; Loop through the no. of items in the listview and display the item text For $i = 0 To $ItemsCount Step 1 MsgBox(0,"Item Text", _GUICtrlListView_GetItemText($hListBoxHandle , $i) Next
wakillon Posted February 23, 2011 Posted February 23, 2011 (edited) Sorry for the misunderstanding I thought your "standalone GUI application containing a ListBox" was an AutoIt script ! Edited February 23, 2011 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts
Sreekanth Posted February 23, 2011 Author Posted February 23, 2011 Hi, It is an AutoIt script only. I am writing in SciTi editor, Part of the script posted on the forum. Is there any way to get the item text from the listbox? Please help me.
wakillon Posted February 23, 2011 Posted February 23, 2011 (edited) Ok It is strange that you get the handle and the count of items without the title of the window and just the controlid ! There is really no title ? try ControlGetHandle ( "[CLASS:ListBox]", "", "ListBox3" ) Edit : i don't see any error in your script so i think that handle is bad. Edited February 23, 2011 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts
Sreekanth Posted February 23, 2011 Author Posted February 23, 2011 Window Title is the main application window which is there, to create the handle I am using ClassnameNN in place of controlID in ControlGetHandle funcion. Tried this and no luck - ControlGetHandle ( "[CLASS:ListBox]", "", "ListBox3" ), no handle returned for the control.
wakillon Posted February 23, 2011 Posted February 23, 2011 Window Title is the main application window which is there, to create the handle I am using ClassnameNN in place of controlID in ControlGetHandle funcion. Tried this and no luck - ControlGetHandle ( "[CLASS:ListBox]", "", "ListBox3" ), no handle returned for the control. Can you try your method for see if there is an error. $hListBoxHandle = ControlGetHandle("", "", "ListBox3") ConsoleWrite ( "@error : " & @error & @Crlf ) ConsoleWrite ( "$hListBoxHandle : " & $hListBoxHandle & @Crlf ) AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts
Moderators Melba23 Posted February 23, 2011 Moderators Posted February 23, 2011 wakillon,It is strange that you get the handle and the count of items without the title of the window and just the controlid !If you do not enter "Title" and "text" parameters, AutoIt will usually (but not not guaranteed) default to the active window. so it is not really surprising. Sreekanth,I am confused - although that is not difficult to do. Is the ListBox you are trying to read one created in another AutoIt script? Or is it in the same script in which you are trying to read the contents? M23 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: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Sreekanth Posted February 23, 2011 Author Posted February 23, 2011 wakillon,If you do not enter "Title" and "text" parameters, AutoIt will usually (but not not guaranteed) default to the active window. so it is not really surprising. Sreekanth,I am confused - although that is not difficult to do. Is the ListBox you are trying to read one created in another AutoIt script? Or is it in the same script in which you are trying to read the contents? M23@M23:ListBox is not created in the autoit script i am writing, it is in a standalone win32 application. I am writing the script to test the controls and perform some actions on the controls like button clicking, reading listbox contents etc.
wakillon Posted February 23, 2011 Posted February 23, 2011 (edited) wakillon,If you do not enter "Title" and "text" parameters, AutoIt will usually (but not not guaranteed) default to the active window. so it is not really surprising. M23I know this, but like i don't find errors in his script i thinked that handle was wrong. Edited February 23, 2011 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts
Moderators Melba23 Posted February 23, 2011 Moderators Posted February 23, 2011 Sreekanth,Are you sure that the GUI CLASS is "ListBox" - that sounds to me like the clas of the control of which your list is INSTANCE:3. What does the Window Info tool tell you about the window CLASS? Perhaps you could post what you get in the Window and Control tabs of the tool so we can take a look. M23 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: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Sreekanth Posted February 23, 2011 Author Posted February 23, 2011 Sreekanth, Are you sure that the GUI CLASS is "ListBox" - that sounds to me like the clas of the control of which your list is INSTANCE:3. What does the Window Info tool tell you about the window CLASS? Perhaps you could post what you get in the Window and Control tabs of the tool so we can take a look. M23 @M23: Here is the info.. Class ListBox Instance 3 ClassnameNN ListBox3 Advanced Mode [CLASS:ListBox; INSTANCE:3] I have attached the screenshot of the Info tool in my first post.
Moderators Melba23 Posted February 23, 2011 Moderators Posted February 23, 2011 Sreekanth,That is the info for the CONTROL - we also need the info for the WINDOW on the first tab of the tool.M23P.S. When you reply please use the "Add Reply" button at the top and bottom of the page rather then the "Reply" button in the post itself. That way you do not get the contents of the previous post quoted in your reply and the whole thread becomes easier to read. 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: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
misterDee Posted February 23, 2011 Posted February 23, 2011 This is not a list-view control, autoit window info saying it is listbox control - CLASS: ListBox. How can I use ListView?Even I tried using ListView control, now even item count is showing 0 and item text is displayed nothing during the loop.; Create a handle for listview$hListBoxHandle = ControlGetHandle("", "", "ListBox3"); Get Items count in the list view$ItemsCount= _GUICtrlListView_GetItemCount($hListBoxHandle )MsgBox(0,"UI Listbox Items count",$ItemsCount); Loop through the no. of items in the listview and display the item textFor $i = 0 To $ItemsCount Step 1MsgBox(0,"Item Text", _GUICtrlListView_GetItemText($hListBoxHandle , $i)NextThnx, good loop! (Y)
Sreekanth Posted February 23, 2011 Author Posted February 23, 2011 Window Info Title Sample Title Class #32770 Position 310, 316 Size 457, 394 Style 0x14CF0844 ExStyle 0x00010100 Handle 0x0018093C
Moderators Melba23 Posted February 23, 2011 Moderators Posted February 23, 2011 (edited) Sreekanth, OK, so now we try this and see what we get: ; Create a handle for list box - use full ID $hListBoxHandle = ControlGetHandle("Sample Title", "", "[CLASS:ListBox;INSTANCE:3]") ; You can check with the Window Info tool to see if you get the correct handle ; If not then try [CLASS:#32770] in place of the title text ; Get Items count in the list box $ItemsCount= _GUICtrlListBox_GetCount($hListBoxHandle ) MsgBox(0,"UI Listbox Items count",$ItemsCount) ; Loop through the no. of items in the listbox and display the item text For $i = 0 To $ItemsCount Step 1 MsgBox(0,"Item Text", _GUICtrlListBox_GetText($hListBoxHandle , $i) Next Fingers crossed! M23 Edit: Curly insted of straight bracket - sorry. Edited February 23, 2011 by Melba23 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: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Sreekanth Posted February 23, 2011 Author Posted February 23, 2011 I am getting the correct handle and listbox items count, but not able to get the item text, in all the 3 iterations item text is blank
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now