Jump to content

Not sure why this ListView_GetItemText not working..


Recommended Posts

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

Link to comment
Share on other sites

  • Moderators

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

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:

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

 

Link to comment
Share on other sites

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

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

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

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

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

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.

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

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

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
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

Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...