Sign in to follow this  
Followers 0
Damein

Not sure why this ListView_GetItemText not working..

5 posts in this topic

#1 ·  Posted (edited)

Alright, so I have this as an example:

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

Opt("GUIOnEventMode", 1)

$Gui = GuiCreate("Test", 400,500)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$TreeView = GUICtrlCreateTreeView(10, 10, 100, 300)
$TreeViewItem = GUICtrlCreateTreeViewItem("Test", $TreeView)
$TreeViewItemSub = GUICtrlCreateTreeViewItem("Sub Test", $TreeViewItem)
$ListView = GUICtrlCreateListView("List", 160, 10, 200, 200)
_GUICtrlListView_AddItem($ListView, "TestItem")
_GUICtrlListView_AddItem($ListView, "TestItem2")
_GUICtrlListView_AddItem($ListView, "TestItem3")
GuiCtrlCreateButton("Read", 20, 400)
GUICtrlSetOnEvent(-1, "_Read")
GuiSetState()

Func _Read()
    $Index = ControlListView($Gui, "Test", $ListView,"GetSelected")
    $txt = _GUICtrlListView_GetItemText($ListView, $Index)
    MsgBox(0, "Test", "Index: " & $Index & @CRLF & "Data: " & $txt)
EndFunc

Func _Exit()
    Exit
EndFunc

While 1
    Sleep(10)
WEnd 

Now the MsgBox for $index shows the correct number but the MsgBox for $txt is blank. But if I manually set $Index = 1 the MsgBox for $txt show's the data for that item...

Can the GetItemText not use a variable for it's count or am I doing something wrong here?

Thanks!

Edited by Damein

MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Share this post


Link to post
Share on other sites



Damein,

You are creating the ListView using the native function and adding the items using the UDF function - a sure recipe for tears. As a result, you are not getting the correct value for ControlId/handle to use with _GUICtrlListView_GetItemText. Best to stick with the native functions like this:

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

Opt("GUIOnEventMode", 1)

$Gui = GUICreate("Test", 400, 500)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$TreeView = GUICtrlCreateTreeView(10, 10, 100, 300)
$TreeViewItem = GUICtrlCreateTreeViewItem("Test", $TreeView)
$TreeViewItemSub = GUICtrlCreateTreeViewItem("Sub Test", $TreeViewItem)
$ListView = GUICtrlCreateListView("List           ", 160, 10, 200, 200)
GUICtrlCreateListViewItem("TestItem1", $ListView)
GUICtrlCreateListViewItem("TestItem2", $ListView)
GUICtrlCreateListViewItem("TestItem3", $ListView)
GUICtrlCreateButton("Read", 20, 400)
GUICtrlSetOnEvent(-1, "_Read")
GUISetState()

Func _Read()
    $txt = StringTrimRight(GUICtrlRead(GUICtrlRead($ListView)), 1)
    MsgBox(0, "Test", "Data: " & $txt)
EndFunc   ;==>_Read

Func _Exit()
    Exit
EndFunc   ;==>_Exit

While 1
    Sleep(10)
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

#3 ·  Posted (edited)

Dunno, doesn't work here either, but when i change

$Index = ControlListView($Gui, "Test", $ListView,"GetSelected")

For

$Index = _GUICtrlListView_GetNextItem($ListView, -1, 0, 8)

It works, so there must be a problem with

$Index = ControlListView($Gui, "Test", $ListView,"GetSelected"), parameters seem correct..

EDIT: arrived too late

Edited by careca

Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

 

Share this post


Link to post
Share on other sites

I'll look over your stuff Melba but I thought I'd post what I tried randomly and got to work.. which I don't think should of worked! Lol!

Seem's to be a weird bug, obviously it has problems with a variable being used if no number is presented so I tried this and viola it works perfectly.

$Text = _GUICtrlListView_GetItemText($ListView, 0+$Index)

So in full:

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

Opt("GUIOnEventMode", 1)

$Gui = GuiCreate("Test", 400,500)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$TreeView = GUICtrlCreateTreeView(10, 10, 100, 300)
$TreeViewItem = GUICtrlCreateTreeViewItem("Test", $TreeView)
$TreeViewItemSub = GUICtrlCreateTreeViewItem("Sub Test", $TreeViewItem)
$ListView = GUICtrlCreateListView("List", 160, 10, 200, 200)
_GUICtrlListView_AddItem($ListView, "TestItem")
_GUICtrlListView_AddItem($ListView, "TestItem2")
_GUICtrlListView_AddItem($ListView, "TestItem3")
GuiCtrlCreateButton("Read", 20, 400)
GUICtrlSetOnEvent(-1, "_Read")
GuiSetState()

Func _Read()
    $Index = ControlListView($Gui, "Test", $ListView,"GetSelected")
    $Text = _GUICtrlListView_GetItemText($ListView, 0+$Index)
    MsgBox(0, "Test", "Index: " & $Index & @CRLF & "Data: " & $Text)
EndFunc

Func _Exit()
    Exit
EndFunc

While 1
    Sleep(10)
WEnd

MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Beginning with ControlListview why didn't you continue ?

$txt = ControlListView($Gui, "Test", $ListView,"GetText", $Index)

:)

Edit

BTW the helpfile is clear about ControlListview(.... , "GetSelected") :

"Returns a string containing the item index of selected items"

so this works

$txt = _GUICtrlListView_GetItemText($ListView, Number($Index))
Edited by mikell
1 person likes this

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