Sign in to follow this  
Followers 0
kylomas

[SOLVED] _guictrllistview_getitem not returning data

6 posts in this topic

#1 ·  Posted (edited)

Good Evening,

The following function produces a listview from an sqlite table using native listview functions. I can detect that an item has focus and has been selected but I cannot get the text of the item. I have tried using both the handle and control id of the listview control, both without sucess.

My purpose is to create a simple list manager (update, add, delete) to maintain an sqlite table. Perhaps I am going about it the wrong way.

func gui10()
local $lvhdrstr
local $gui010 = guicreate("Kylomas - HUH Manager - List Screen",1200,850)
for $i = 1 to 14
$lvhdrstr &= "|" & $a_field_names[$i]
next
local $lst010 = GUICtrlCreateListView($lvhdrstr,10,10,1180,800,default,$lvs_ex_fullrowselect)
locaL $HLST010 = GUICTRLGETHANDLE($LST010)
local $edtBTN = guictrlcreatebutton("Edit",10,815,50,30)
local $delBTN = guictrlcreatebutton("Delete",90,815,50,30)
local $addBTN = guictrlcreatebutton("Add",170,815,50,30)
local $ret, $hdb, $rows, $nbrows, $nbcols, $sqlstr
local $ret = _SQLite_GetTable2d(-1, "select * from HUH;", $rows, $nbrows, $nbcols)
If @error Then consolewrite("!> Error getting HUH Data" & @lf)
for $i = 0 to $nbrows - 1
$lvhdrstr = ""
for $j = 0 to $nbcols - 1
$lvhdrstr &= "|" & $rows[$i][$j]
Next
GUICtrlCreateListViewItem($lvhdrstr,$lst010)
next
GUISetState()
while 1
local $msg = guigetmsg()
switch $msg
case $gui_event_close
    Exit
case $edtBTN
    for $i= 0 to _GUICtrlListView_GetItemCount($hlst010)
     local $aitem = _GUICtrlListView_GetItem($hlst010,$i)
     if $aitem[0] = 12 then
     consolewrite("! > Item selected is " & $aitem[3] & @lf)
     _arraydisplay($aitem)
     EndIf
    next
EndSwitch
wend
endfunc

Thanks,

kylomas

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites



The $edtButton has focus, not the listview item, change it to If $aitem[0] = 8 instead of 12.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

@BrewmanNH

Thanks for the fast reply. Unfortunately that is not the problem. The test for 8 (item selected) returns false for all items. I added a consolewrite specifying the index into the listview and it does not work either (similar to the example in the help file). The following is my code with the debugging consolewrite. I am working on a reproducer to make the problem clearer (I'll probably stumble across the solution while making the reproducer !).

func gui10()
 local $lvhdrstr
 local $gui010 = guicreate("Kylomas - HUH Manager - List Screen",1200,850)
 for $i = 0 to 14
  $lvhdrstr &= "|" & $a_field_names[$i]
 next
 local $lst010  =  GUICtrlCreateListView($lvhdrstr,10,10,1180,800,default,$lvs_ex_fullrowselect)
 locaL $HLST010  =  GUICTRLGETHANDLE($LST010)
 local $edtBTN   =   guictrlcreatebutton("Edit",10,815,50,30)
 local $delBTN   =   guictrlcreatebutton("Delete",90,815,50,30)
 local $addBTN   =   guictrlcreatebutton("Add",170,815,50,30)
 local $ret, $hdb, $rows, $nbrows, $nbcols, $sqlstr
 local $ret = _SQLite_GetTable2d(-1, "select * from HUH;", $rows, $nbrows, $nbcols)
    If @error Then consolewrite("!>  Error getting HUH Data" & @lf)
 for $i = 0 to $nbrows - 1
  $lvhdrstr = ""
  for $j = 0 to $nbcols - 1
   $lvhdrstr &= "|" & $rows[$i][$j]
  Next
  GUICtrlCreateListViewItem($lvhdrstr,$lst010)
 next
 GUISetState()
 local $test = _GUICtrlListView_GetItem($lst010, 12)     ;<<<<<   added as test from help file
    consolewrite("+>>> listview item test =  " & $test[3] & @lf)  ;<<<<<   does NOT work
 while 1
  local $msg = guigetmsg()
  switch $msg
   case $gui_event_close
    Exit
   case $edtBTN
    for $i= 0 to _GUICtrlListView_GetItemCount($hlst010)
     local $aitem = _GUICtrlListView_GetItem($hlst010,$i)
     if $aitem[0] = 12 then
      consolewrite("! > Item selected is " & $aitem[3] & @lf)
      _arraydisplay($aitem)
     EndIf
    next
  EndSwitch
 wend
endfunc

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Try using _GUICtrlListView_GetSelectedIndices to see if you can identify the selected item, then pull the text from the selected item using _GUICtrlListView_GetItemTextString to see if it's reading the right item.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

@BrewmanNH,

Thanks for your help. After much jerking around this is what finally worked.

; *** Start added by AutoIt3Wrapper ***
#include <ListViewConstants.au3>
; *** End added by AutoIt3Wrapper ***
; *** Start added by AutoIt3Wrapper ***
#include <WindowsConstants.au3>
; *** End added by AutoIt3Wrapper ***
; *** Start added by AutoIt3Wrapper ***
#include <EditConstants.au3>
; *** End added by AutoIt3Wrapper ***
; *** Start added by AutoIt3Wrapper ***
#include <GUIConstantsEx.au3>
; *** End added by AutoIt3Wrapper ***
#AutoIt3Wrapper_Add_Constants=n
#include <array.au3>
#include <date.au3>
#include <file.au3>
#include <string.au3>
#include <sqlite.au3>
#include <guilistview.au3>
;
; startup sqlite and open kylomas DB
;
Global $hDB
Local $DllPath = _SQLite_Startup(Default, 1)
If @error Then
 MsgBox(0, "Fatal", "sqlite3.dll can't be found.")
 Exit
EndIf
OnAutoItExitRegister("_SQLite_ShutDown")
ConsoleWrite("Using " & $DllPath & @LF)
_SQLite_SafeMode(0)
$hDB = _SQLite_Open()
If @error Then
 ConsoleWrite("@error = " & @error & ', @extended = ' & @extended & @LF)
 MsgBox(0, "Fatal", "Error opening DB.")
 Exit
EndIf
local $a_field_names[05] = ['item10', 'item20', 'item30', 'item40', 'item50']
$ret = _SQLite_Exec (-1, "CREATE TABLE [test] (item10, item20, item30, item40, item50);")
if $ret <> $sqlite_ok then consolewrite("! SQLite Error " & _SQLite_ErrMsg ())
for $i = 1 to 20
 $ret = _SQLite_Exec($hDB, 'insert into test (item10, item20, item30, item40, item50)' & _
     'values (' & _
     '"item10' & $i & '"' & _
     ', "item20' & $i & '"' & _
     ', "item30' & $i & '"' & _
     ', "item40' & $i & '"' & _
     ', "item50' & $i & '");')
 if $ret <> $sqlite_ok then consolewrite("! SQLite Error " & _SQLite_ErrMsg ())
next
gui10()
func gui10()
 local $lvhdrstr
 local $gui010 = guicreate("Kylomas - HUH Manager - List Screen",1200,850)
 for $i = 0 to 4
  $lvhdrstr &= "|" & $a_field_names[$i]
 next
 local $lst010  =  GUICtrlCreateListView($lvhdrstr,10,10,1180,800,default,$lvs_ex_fullrowselect)
 locaL $HLST010  =  GUICTRLGETHANDLE($LST010)
 local $edtBTN   =   guictrlcreatebutton("Edit",10,815,50,30)
 local $delBTN   =   guictrlcreatebutton("Delete",90,815,50,30)
 local $addBTN   =   guictrlcreatebutton("Add",170,815,50,30)
 local $ret, $hdb, $rows, $nbrows, $nbcols, $sqlstr
 local $ret = _SQLite_GetTable2d(-1, "select * from test;", $rows, $nbrows, $nbcols)
    If @error Then consolewrite("!>  Error getting HUH Data" & @lf)
 for $i = 0 to $nbrows - 1
  $lvhdrstr = ""
  for $j = 0 to $nbcols - 1
   $lvhdrstr &= "|" & $rows[$i][$j]
  Next
  GUICtrlCreateListViewItem($lvhdrstr,$lst010)
 next
 GUISetState()
 while 1
  local $msg = guigetmsg()
  switch $msg
   case $gui_event_close
    Exit
   case $edtBTN
    consolewrite("! > " & _GUICtrlListView_GetItemTextString ($hlst010,-1) & @lf)
  EndSwitch
 wend
endfunc

Note: function is wrapped in a reproducer.

I suppose that you need to tear the udf apart to understand the difference between similar sounding functions, e.g. _guictrllistview_getitemtextstring and _guictrllistview_getitem...

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

I missed the -1 parameter to get the currently selected item, saves having to write another function call that way.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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