Jump to content

How do I find which item/row selected in listview?


 Share

Recommended Posts

How do I see which item/row they selected when I process the button event?

Relevant code stub is below:

func theview_select()

$aItem1=_GUICtrlListView_GetHotItem($listview)

$aItem2 = _GUICtrlListView_GetItemTextArray($listview, -1)

Msgbox(64,"viewselect aItem","Value:" & $aItem1 & "; " & $aItem2)

EndFunc

Func theview() ;button

$child=GUICreate("Reminder Event Details", 500, 400); BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_SIZEBOX))

GUISetOnEvent($GUI_EVENT_CLOSE, 'guiexit3')

GUICtrlCreateLabel("REMINDER: View Event",100,10,-1,-1)

GUISetBkColor(0x88AABB)

GUICtrlCreateButton("SELECT",400,50,50,20)

GUICtrlSetOnEvent(-1,"theview_select")

GUICtrlCreateButton("VIEW",400,100,50,20)

GuiCtrlSetOnevent(-1,'theview_view')

GUICtrlCreateButton("DELETE",400,150,50,20)

GUICtrlSetOnEvent(-1,'theview_delete')

GUICtrlCreateButton("HELP",400,250,50,20)

GUICtrlSetOnEvent(-1,'theview_help')

GUICtrlCreateButton("QUIT",400,200,50,20)

GUICtrlSetOnEvent(-1,"guiexit3")

$blanks=" "

$listview =GUICtrlCreateListView("Seq#|Date|Time|Text" & $blanks, 10, 10, 350, 350) ;,$LVS_SORTDESCENDING)

$rows=UBound($eventArray)-1

For $x = 0 To $rows ;we load upcoming data from our arrays

;$eventArray=(yyyymmddhhmm, text) (2 columns per row)

$timed=$eventArray[$x][0] ;yyyymmddhhmm

$textd=$eventArray[$x][1] ;text of reminder

if(FALSE=StringRegExp("^|",$textd)) Then

$ddate=StringLeft($timed,8) ;yymmdd

$dtime=StringRight($timed,4) ;hhmm

$ts=StringLeft($dtime,2) & ":" & StringRight($dtime,2) ; hhmm -> hh:mm

GUICtrlCreateListViewItem($x & "|" & $ddate & "|"& $ts & "|" & $textd, $listview);

EndIf

Next

;GUICtrlSetResizing($listview, $GUI_DOCKALL)

GUISetState(@SW_SHOW)

EndFunc

Thanks in advance

Joe

joec_49@hotmail.com

Link to comment
Share on other sites

Help file quote:

_GUICtrlListView_GetItemSelected

--------------------------------------------------------------------------------

Determines whether the item is selected

#Include <GuiListView.au3>

_GUICtrlListView_GetItemSelected($hWnd, $iIndex)

Parameters

$hWnd Handle to the control

$iIndex Zero based index of the item

Return Value

Success: True

Failure: False

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

GUICtrlListView_GetSelectedIndices

Thanks - works great! But how do I then get the selected text:

func theview_select()

$aItem1=_GUICtrlListView_GetSelectedIndices($listview,False); gives me what item# is selected

if($aItem1 = "") Then

msgBox(64,"ZIP","nothing selected")

else ;gives me row/item# in 0-based origin

$text=_GUICtrlListView_GetItemText($listview,$aItem1,-1)

Msgbox(64,"viewselect aItem","Value:" & $aItem1 & ";" & $text)

endif

EndFunc

The $text variable is always blank??

Link to comment
Share on other sites

Thanks - works great! But how do I then get the selected text:

func theview_select()

$aItem1=_GUICtrlListView_GetSelectedIndices($listview,False); gives me what item# is selected

if($aItem1 = "") Then

msgBox(64,"ZIP","nothing selected")

else ;gives me row/item# in 0-based origin

$text=_GUICtrlListView_GetItemText($listview,$aItem1,-1)

Msgbox(64,"viewselect aItem","Value:" & $aItem1 & ";" & $text)

endif

EndFunc

The $text variable is always blank??

If only 1 item is selected you'll have to cast it to an integer

$text=_GUICtrlListView_GetItemText($listview,Int($aItem1),-1)

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

GaryFrost

If only 1 item is selected you'll have to cast it to an integer

Sorry, but if the item is a string?

I think his error in last parameter _GUICtrlListView_GetItemText($listview, $aItem1, -1). Should be use 0 instead of -1.

Link to comment
Share on other sites

GaryFrost

Sorry, but if the item is a string?

I think his error in last parameter _GUICtrlListView_GetItemText($listview, $aItem1, -1). Should be use 0 instead of -1.

Didn't catch the -1 but yes $aItem1 is a string. Check the help.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

GaryFrost

With all respects to you. Example from help:

#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>

Opt('MustDeclareVars', 1)

$Debug_LV = False ; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work

_Main()

Func _Main()
    Local $hListView
    
    GUICreate("ListView Get Item Text", 400, 300)
    $hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
    GUISetState()

    ; Add columns
    _GUICtrlListView_AddColumn($hListView, "Items", 100)

    ; Add items
    _GUICtrlListView_AddItem($hListView, "Item 1")
    _GUICtrlListView_AddItem($hListView, "Item 2")
    _GUICtrlListView_AddItem($hListView, "Item 3")

    ; Set item 2 text
    _GUICtrlListView_SetItemText($hListView, 1, "New Item 2")
    MsgBox(4160, "With 0 param", "Item 2 Text: " & _GUICtrlListView_GetItemText($hListView, 1, 0)) ;last param = 0
    MsgBox(4160, "With -1 param", "Item 2 Text: " & _GUICtrlListView_GetItemText($hListView, 1, -1)) ;last param = -1

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main
Link to comment
Share on other sites

GaryFrost

With all respects to you. Example from help:

#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>

Opt('MustDeclareVars', 1)

$Debug_LV = False ; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work

_Main()

Func _Main()
    Local $hListView
    
    GUICreate("ListView Get Item Text", 400, 300)
    $hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
    GUISetState()

    ; Add columns
    _GUICtrlListView_AddColumn($hListView, "Items", 100)

    ; Add items
    _GUICtrlListView_AddItem($hListView, "Item 1")
    _GUICtrlListView_AddItem($hListView, "Item 2")
    _GUICtrlListView_AddItem($hListView, "Item 3")

    ; Set item 2 text
    _GUICtrlListView_SetItemText($hListView, 1, "New Item 2")
    MsgBox(4160, "With 0 param", "Item 2 Text: " & _GUICtrlListView_GetItemText($hListView, 1, 0)) ;last param = 0
    MsgBox(4160, "With -1 param", "Item 2 Text: " & _GUICtrlListView_GetItemText($hListView, 1, -1)) ;last param = -1

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main

Wrong part of the help file, check what _GUICtrlListView_GetSelectedIndices($listview, False) returns.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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...