david1337

Show item from list

16 posts in this topic

Hey guys

Quick question:

In this GUI the listview is created from items in test.txt

I would like my "Get Info" button to show the actual text of the item that is selected. So far I have been able to make it show the number of the item.

What is the last missing puzzle here?
 

#include <GUIConstantsEx.au3>
#include <GUIListViewEx.au3>


Global $MainGUI_ManageItemList
Global $File = "test.txt"
Global $FileToArray = FileReadToArray("test.txt")



Call ("MainGUI_ManageItemList")



Func MainGUI_ManageItemList()

    Local $Button1

    $MainGUI_ManageItemList = GUICreate("Manage Item List", 800, 400, -1, -1)

    $cLV = GUICtrlCreateListView("[items]", 10, 10, 400, 775, $LVS_NOCOLUMNHEADER)
GUICtrlSetFont(-1, 12, 800, 0, "@Arial Unicode MS")
_GUICtrlListView_SetColumnWidth($cLV, 0, 378)

$Button1 = GUICtrlCreateButton("Button 1", 425, 10, 80, 30)
$RemoveItem = GUICtrlCreateButton("Remove Item", 425, 50, 80, 30)
$GetInfo = GUICtrlCreateButton("GetInfo", 425, 120, 80, 30)


GUISetState(@SW_SHOW, $MainGUI_ManageItemList)



; Intialise ListView
Global $iLV_Index = _GUIListViewEx_Init($cLV)
; Insert lines
_GUIListViewEx_Insert($FileToArray, True)
; Register required messages
_GUIListViewEx_MsgRegister(True, False, False, False)


    While 1
        Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE

                ExitLoop

            Case $Button1
            MsgBox(0,"","Button 1 is pressed")


         Case $RemoveItem
            _GUIListViewEx_Delete()

         Case $GetInfo
         $iIndex = _GUICtrlListView_GetSelectedIndices($cLV)
         msgbox (0, "Selected item", $iIndex)

        EndSwitch
    WEnd
EndFunc   ;==>Main

 

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Bill ! My new best friend :)

If I define the item number like this: _GUICtrlListView_GetItemText($cLV, 1)  Then it shows the text of item 1 correct.

And since _GUICtrlListView_GetSelectedIndices gets the item number of the selected item, I thought that I could do like this, but it doesn't work.
The 2nd msgbox is just blank.

 

Case $GetInfo
$iIndex = _GUICtrlListView_GetSelectedIndices($cLV)

$iIndexText = _GUICtrlListView_GetItemText($cLV, $iIndex)


msgbox (0, "Selected item NUMBER", $iIndex)
msgbox (0, "Selected item TEXT", $iIndexText)

 

Edited by david1337

Share this post


Link to post
Share on other sites
31 minutes ago, david1337 said:

Bill ! My new best friend :)

 

o:)

Try the Array Based Parameter:

Case $GetInfo
         $iIndex = _GUICtrlListView_GetSelectedIndices($cLV, True)
        $iIndexText = _GUICtrlListView_GetItemText($cLV, $iIndex[1])

 

Share this post


Link to post
Share on other sites

Oh, I didn't see your fix - that works great too, and somehow seems prettier :D

Btw do you know if it's possible to set a case as soon as an item in the list is highlighted? Or is a button always needed?

Share this post


Link to post
Share on other sites
39 minutes ago, david1337 said:

Oh, I didn't see your fix - that works great too, and somehow seems prettier :D

Well yours works for now but when you start adding code and intricacies it may cause problems down the road.

Share this post


Link to post
Share on other sites

For instance if you were using the Default Version of _GUICtrlListView_Create you could call your case with the following:

$LVS_EX_ONECLICKACTIVATE - The control sends an $LVN_ITEMACTIVATE messages when the user clicks an item

 

Melbas probably has something similar better ;-)

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Haha I'm sure Melba has something just like that superior :P *poke poke Melba*

Edited by david1337

Share this post


Link to post
Share on other sites

Oh god scripting can be frustrating:

When NO item is selected and the "Get Info" button is clicked, the script crashes with: Array variable has incorrect number of subscripts or subscript dimension range exceeded

I guess that array bug is still haunting here huh? :)

Share this post


Link to post
Share on other sites

david1337,

Someone called?

This seems to work nicely:

Case $GetInfo
    $aIndex = _GUICtrlListView_GetSelectedIndices($cLV, True)
    If IsArray($aIndex) And $aIndex[0] <> 0 Then
        MsgBox(0, "Selected item", _GUICtrlListView_GetItemText( $cLV, $aIndex[1]))
    EndIf

And as you are checking that there is at least one item selected, you do not get a crash when one is not.

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

Melba,

Exactly! Worked perfectly. Clever way to attack the issue :) Thank you!

 

-

 

Now, can I please request for a function like this in the forum?
MelbaSignal.png

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

david1337,

Nice thought - but as has just been proved, I normally turn up fairly quickly in any event!

M23

Edited by Melba23
Typo

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

:lol: You sure do

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

  • Similar Content

    • PINTO1927
      Add .txt to GUICtrlCreateListView
      By PINTO1927
      Hi Guys,
      I'm working on this project:
      $Import = GUICtrlCreateButton("Import", 15, 175, 90, 40, $WS_GROUP) $List = GUICtrlCreateListView("Name|Address|E-mail", 15, 220, 400, 363, $LVS_SORTDESCENDING) $Item1 = GUICtrlCreateListViewItem("test|test|test", $List) GUISetState(@SW_SHOW, $GUI) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE, $Exit Exit Case $Import $Table_Import = FileOpenDialog("Import list '*.txt'", @DesktopDir & "\", "Text (*.txt)") If @error Then ContinueLoop GUICtrlSetData($Item1, $Table_Import) In the text file the fields are delimited with "|" and the values are not in the same row but one below the other.
      However in the txt file the sum of the values may change.
      Can you help me?
      Thank's
    • PINTO1927
      GUICtrlCreateListView Excel
      By PINTO1927
      Hello guys,
      I built a gui where a GUICtrlCreateListView with two columns is present.
      Through an "Import" button I would be able to import the contents of an .xls or .txt.
      Can you help me?
      Thank's
    • AutoBert
      [solved] Set HeaderColumn Color in ListView
      By AutoBert
      I have a LV with different coloured Cols:
      ;https://autoit.de/index.php/Thread/84279-Unterschiedliche-Textfarben-innerhalb-einer-ListView/?postID=674195#post674195 #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <array.au3> #include <ListViewConstants.au3> #include <StructureConstants.au3> #include <WindowsConstants.au3> $aColBK = IniReadSection(@ScriptDir & "\lv_format.ini", "ColBKColor") _ArrayDelete($aColBK, 0) ;_ArrayDisplay($aColBK) $aRowBK = IniReadSection(@ScriptDir & "\lv_format.ini", "RowBKColor") _ArrayDelete($aRowBK, 0) ;_ArrayDisplay($aColBK) $aColText = IniReadSection(@ScriptDir & "\lv_format.ini", "ColTextColor") _ArrayDelete($aColText, 0) ;_ArrayDisplay($aColBK) $aRowText = IniReadSection(@ScriptDir & "\lv_format.ini", "RowTextColor") _ArrayDelete($aRowText, 0) ;_ArrayDisplay($aRowText) $GUI = GUICreate("Listview Farbig", 1024, 300, 0, 0) ;<==== Breite geändert $cListView = GUICtrlCreateListView("", 2, 2, 1020, 294, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) ;<==== Breite geändert $hListView = GUICtrlGetHandle($cListView) For $i = 1 To 31 _GUICtrlListView_InsertColumn($hListView, $i - 1, $i, 25) _GUICtrlListView_SetColumnWidth($hListView, $i - 1, 32) ;<==== eingefügt für Spaltenbreite Next For $i = 0 To 21 ; alle Item/SubItem erstellen _GUICtrlListView_AddItem($hListView, "Item: " &$i, $i) For $j = 1 To 30 _GUICtrlListView_AddSubItem($hListView, $i, "Sub: "&$j, $j) Next Next GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState() While True $msg = GUIGetMsg() Switch $msg Case -3 ExitLoop EndSwitch WEnd Func WM_NOTIFY($hWnd, $msg, $wParam, $lParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListView Switch $iCode Case $NM_CUSTOMDRAW Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam) Local $iDrawStage, $iItem, $iSubitem, $hDC, $tRect $iDrawStage = DllStructGetData($tCustDraw, 'dwDrawStage') Switch $iDrawStage Case $CDDS_ITEMPREPAINT Return $CDRF_NOTIFYSUBITEMDRAW Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM) ; Item/SubItem das aktuell gezeichnet werden soll ermitteln $iItem = DllStructGetData($tCustDraw, 'dwItemSpec') $iSubitem = DllStructGetData($tCustDraw, 'iSubItem') Switch $iItem ; Zeilenwahl Case -1 ;kommt nicht vor ist aber notwendig, damit case else verwendet werden kann Case Else $iIndex = _ArraySearch($aRowBK, $iItem, 0, 0, 0, 0, 1, 0) If $iIndex = -1 Then ;nicht im Array für spezielle Zeilen also weiß DllStructSetData($tCustDraw, 'clrTextBk', RGB2BGR(0xFFFFFF)) Else DllStructSetData($tCustDraw, 'clrTextBk', RGB2BGR($aRowBK[$iIndex][1])) ;ConsoleWrite('Item '&$iItem&' BK: '&$aRowBK[$iIndex][1] & @CRLF) EndIf $iIndex = _ArraySearch($aRowText, $iItem, 0, 0, 0, 0, 1, 0) If $iIndex = -1 Then ;nicht im Array für spezielle Zeilen also schwarz DllStructSetData($tCustDraw, 'clrText', RGB2BGR(0x000000)) Else DllStructSetData($tCustDraw, 'clrText', RGB2BGR($aRowText[$iIndex][1])) ;ConsoleWrite('Item '&$iItem&' Text: '&$aRowText[$iIndex][1] & @CRLF) EndIf EndSwitch Switch $iSubitem Case -1 ;kommt nicht vor ist aber notwendig, damit case else verwendet werden kann Case Else $iIndex = _ArraySearch($aColBK, $iSubitem, 0, 0, 0, 0, 1, 0) If $iIndex <> -1 Then DllStructSetData($tCustDraw, 'clrTextBk', RGB2BGR($aColBK[$iIndex][1])) ;ConsoleWrite('SubItem '&$iSubitem&' BK: '&$aColBK[$iIndex][1] & @CRLF) EndIf $iIndex = _ArraySearch($aColText, $iSubitem, 0, 0, 0, 0, 1, 0) If $iIndex <> -1 Then DllStructSetData($tCustDraw, 'clrText', RGB2BGR($aColText[$iIndex][1])) ;ConsoleWrite('SubItem '&$iSubitem&' Text: '&$aColText[$iIndex][1] & @CRLF) EndIf EndSwitch Return $CDRF_NEWFONT EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func RGB2BGR($iColor) Local $sH = Hex($iColor, 6) Return '0x' & StringRight($sH, 2) & StringMid($sH, 3, 2) & StringLeft($sH, 2) EndFunc ;==>RGB2BGR i use lv_format.ini for defining the cols Background- and Textcolour. Now i want to colour the cols in the LV-Header also, but i can't figure it out.
       

    • handofthrawn
      How to center and size GUICtrlCreateListView
      By handofthrawn
      I am trying to adjust my top column so the column topics are centered and using a bigger font.  However, whenever I use a bigger font the columns stay the same size and I just get a ",,,"
      Does anyone know how to stretch the columns to use the entire box, center it, and increase the font size?  Thanks for any help.
      #include <Misc.au3> #include <Excel.au3> #include <GUIConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> GUICreate("Indications", 410, 280, 590, 85, -1, $WS_EX_ACCEPTFILES) ; Size of box GUISetBkColor(0x00E0FFFF) ; will change background color Local $idListview = GUICtrlCreateListView(" Column | Item | PCI | IDE ", 5, 5, 395, 210) ;,$LVS_SORTDESCENDING) GUICtrlSetFont($idListview, 12) ;GUICtrlSetFont($idListview, 18) ; Font size I would like to use Local $idButton = GUICtrlCreateButton("Close", 150, 220, 90, 55) ; CLOSE BUTTON Local $idItem1 = GUICtrlCreateListViewItem("item211|col22|col23|col34", $idListview) Local $idItem2 = GUICtrlCreateListViewItem("test111|test31|test5|test6", $idListview) GUICtrlSetState(-1, $GUI_DROPACCEPTED) ; to allow drag and dropping GUISetState(@SW_SHOW) ;GUICtrlDelete($idItem1) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idButton ExitLoop Case $idListview EndSwitch WEnd  
    • reb
      GUICtrlCreateListView
      By reb
      Happy New year to all.

      when I run the program without using $LVS_EX_GRIDLINES I get the Index and the subitem values correctly.
      when I run the program using $LVS_EX_GRIDLINES I get the Index always = -1 and the subitem values are correct.
      What do I need to do to get the correct index and subitem using the gridlines?

      right click a sub item to view in Console.
      REB
       
      #Region - Includes #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <ListViewConstants.au3> #EndRegion - Includes #Region - Variables Local $width = @DesktopWidth, $wheight = @DesktopHeight - 30, $COLOR_GUI = 0xFFFFFF, $lvtop = 100, $index, $subitem #Region -Create GUI GUICreate("Test WM_NOTIFY()", $width, $wheight - 150, 0, 0) ;@DesktopWidth, @DesktopHeight, 0, 0) ; GUISetBkColor(0xF0F4F9) ; $COLOR_GUI) GUISetState() #EndRegion -Create GUI GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") #Region - Create Listview $g_idListView = GUICtrlCreateListView("", 0, $lvtop, $width, $wheight - $lvtop - 150, $LVS_REPORT, $LVS_EX_GRIDLINES) ;~ $g_idListView = GUICtrlCreateListView("", 0, $lvtop, $width, $wheight - $lvtop - 50, $LVS_REPORT) #Region - Add Columns ; Add columns _GUICtrlListView_InsertColumn($g_idListView, 0, 0, 30) For $i = 1 To 15 Step 3 _GUICtrlListView_InsertColumn($g_idListView, $i, "TOTAL = 100", 105 + 31) _GUICtrlListView_InsertColumn($g_idListView, $i + 2, "PHASE", 65) _GUICtrlListView_InsertColumn($g_idListView, $i + 3, "", 22) Next _GUICtrlListView_InsertColumn($g_idListView, $i, "TOTAL =", 105 + 31) _GUICtrlListView_InsertColumn($g_idListView, $i + 2, "PHASE", 65) GUICtrlSetFont($g_idListView, 13, 700, Default, "Courier New", 4) ;~ GUICtrlSetState($g_idListView, $GUI_SHOW) For $i = 1 To 50 _GUICtrlListView_AddItem($g_idListView, $i, 0) Next Local $jump = -2 For $i = 1 To 6 $jump = $jump + 3 _GUICtrlListView_SetItem($g_idListView, " 100", 0, $jump) _GUICtrlListView_SetItem($g_idListView, 1, 0, $jump + 1) Next #EndRegion - Add Columns #EndRegion - Create Listview #Region - Loop Do $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE, $idOK ExitLoop EndSwitch Until $msg = $GUI_EVENT_CLOSE #EndRegion - Loop GUIDelete() Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $index, $subitem Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo $hWndListView = $g_idListView If Not IsHWnd($g_idListView) Then $hWndListView = GUICtrlGetHandle($g_idListView) $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the right mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) $index = DllStructGetData($tInfo, "Index") ;& @CRLF & _ $subitem = DllStructGetData($tInfo, "SubItem") ;& @CRLF & _ EndSwitch ConsoleWrite("Index = " & $index & @CRLF) ConsoleWrite("subitem = " & $subitem & @CRLF) EndSwitch EndFunc ;==>WM_NOTIFY