Jump to content
TheDcoder

Track ListViewItems in a ListView

Recommended Posts

Hello! I want to keep track of all the ListViewItems in a ListView:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 267, 206, 192, 124)
$ListView1 = GUICtrlCreateListView("Col 1|Col 2", 8, 8, 250, 150)
$Button1 = GUICtrlCreateButton("Get Extended", 8, 168, 251, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUICtrlCreateListViewItem("Foo|Bar", $ListView1) ; Extended: Comman Placeholders
GUICtrlCreateListViewItem("Baz|Qux", $ListView1) ; Extended: Rare Placeholders

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
            
        Case $Button1
            ; ...?

    EndSwitch
WEnd

In the above example situation, I want to get the extended text (commented after each ListViewItem) for the the ListViewItem... If I select Foo & Bar (1st Item) and press "Get Extended" a MsgBox should display "Comman Placeholders"

 

Thanks in Advance, TD :)

 

P.S The items are dynamically created in my program and the extended information is stored in a array


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) mean to do that to anybody!!!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

This is a perfect situation to use maps, I hope it may release soon! :D


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) mean to do that to anybody!!!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

TheDcoder,

The items are dynamically created in my program and the extended information is stored in a array

And what is the link between the two? How do you determine which element of the extended information array relates to the selected ListView item?

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

 

Share this post


Link to post
Share on other sites

And what is the link between the two?

Each Item has a path associated...

How do you determine which element of the extended information array relates to the selected ListView item?

That is what I was looking for :P


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) mean to do that to anybody!!!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

TheDcoder,

Assuming that you create the extended information at the same time as a ListView row, you can use an array to very easily link the two elements:

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

Global $aData[2][2] = [["Foo|Bar", "Comman Placeholder"], ["Baz|Qux", "Rare Placeholders"]]

$Form1 = GUICreate("Form1", 267, 206, 192, 124)
$ListView1 = GUICtrlCreateListView("Col 1|Col 2", 8, 8, 250, 150)
$Button1 = GUICtrlCreateButton("Get Extended", 8, 168, 251, 25)
GUISetState(@SW_SHOW)

For $i = 0 To UBound($aData) - 1
    GUICtrlCreateListViewItem($aData[$i][0], $ListView1)
Next

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg

        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
            $iIndex = _GUICtrlListView_GetSelectedIndices($ListView1)
            If $iIndex <> "" Then
                MsgBox($MB_SYSTEMMODAL, "Extended", $aData[$iIndex][1])
            EndIf



    EndSwitch
WEnd

Just add a new row to the array each time you create a ListView row.

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

 

Share this post


Link to post
Share on other sites

@Melba23 Just what I was looking for, Thanks you! :thumbsup:


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) mean to do that to anybody!!!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

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

    • By Slipk
      Hello everybody,
      #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> #include <GUIListViewEx.au3> $Form1 = GUICreate("Form1", 539, 350, 192, 124) $ListView1 = GUICtrlCreateListView("CLM1|CLM2", 0, 0, 538, 326) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 150) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 150) Local $dynamic = GUICtrlCreateListViewItem("Example1|Example2", $ListView1) $SubMenu = GUICtrlCreateContextMenu($dynamic) $Run = GUICtrlCreateMenuItem("Run", $SubMenu) $Edit = GUICtrlCreateMenuItem("Edit", $SubMenu) $Delete = GUICtrlCreateMenuItem("Delete", $SubMenu) Local $dynamic2 = GUICtrlCreateListViewItem("Example3|Example6", $ListView1) $SubMenu = GUICtrlCreateContextMenu($dynamic2) $Run = GUICtrlCreateMenuItem("Run", $SubMenu) $Edit = GUICtrlCreateMenuItem("Edit", $SubMenu) $Delete = GUICtrlCreateMenuItem("Delete", $SubMenu) _GUIListViewEx_Init($ListView1, "", 0, 0, True, 64) _GUIListViewEx_MsgRegister() GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd I use GUIListViewEx.au3 for position of items in listview but when I move one the context menu disappear. Any solution of this?
      Any method than array it is possible?
      Thank you, appreciate it.
       
       
    • By Slipk
      Hello everybody,
      I download the GUIListViewEx.au3 by Melba23 in order to move up or down my items from a listview.
      Everything it's looking good in script but when I move an item it will crash.
      Any suggestions?
      Thank you! 

    • By Slipk
      Hello everybody,
      Sorry for my bad english.
       
      I try to figure out if I have a dynamic listview with as many items as I want, how to save to a text file all the data listview contains in the same form that you put when you create a listviewitem. I will give you an example.
      When the script is running it will show you the listview and some items. How to take the items data "Data1|Data1_Sub1|Data1_Sub2" in this format and paste into a text file? All of them.
      I tried to explain as good as I can.
      Thank you for your attention!
      #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> $Form_Menu = GUICreate("Form Example", 351, 234, -1, -1) $Form_Menu_ListView1 = GUICtrlCreateListView("Column #1|Column #2|Column #3", 0, 0, 346, 230) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 75) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 75) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 75) GUICtrlCreateListViewItem("Data1|Data1_Sub1|Data1_Sub2", $Form_Menu_ListView1) GUICtrlCreateListViewItem("Data2|Data2_Sub1|Data2_Sub2", $Form_Menu_ListView1) GUICtrlCreateListViewItem("DataN|DataN_SubN|DataN_SubN", $Form_Menu_ListView1) ;The data that appear in the listview be saved in a file like that : #cs Data1|Data1_Sub1|Data1_Sub2 Data2|Data2_Sub1|Data2_Sub2 DataN|DataN_SubN|DataN_SubN #ce GUISetState(@SW_SHOW, $Form_Menu) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd
    • By Slipk
      Hello,
      I tried with many methods and searched a lot for items to move up and down but couldn't find it.
      Sorry for my bad english.
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 307, 247, 192, 124) GUISetFont(10, 400, 0, "Arial") $ListView1 = GUICtrlCreateListView("C1|C2|C3", 0, 0, 250, 246) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 60) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 100) GUICtrlCreateListViewItem("Test1|Test2|Test3", $ListView1) GUICtrlCreateListViewItem("Cat|Dog|Fish", $ListView1) GUICtrlCreateListViewItem("ABC|DEF|GHI", $ListView1) $Button1 = GUICtrlCreateButton("/\", 264, 8, 27, 25) GUICtrlSetFont(-1, 10, 800, 0, "Arial") $Button2 = GUICtrlCreateButton("\/", 264, 40, 27, 25) GUICtrlSetFont(-1, 10, 800, 0, "Arial") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1     $nMsg = GUIGetMsg()     Switch $nMsg         Case $GUI_EVENT_CLOSE             Exit         Case $Button1 ;up         Case $Button2 ;down     EndSwitch WEnd  
      Thank you for your help!
    • By Broihon
      Hey guys,

      I ran into a problem when I wanted to delete items of a listview using the delete key. My approach is to register my own WndProc for the listview and then filter the $WM_GETDLGCODE msg and then call the original WndProc.
      That works like a charm. The problem is that when the listview gets redrawn it somehow ends up in an infinite loop. The listview is suddenly emtpy and I can't interact with any controls of the GUI at all. Here's the code:
       
      #include <GUIConstantsEx.au3> #include <GUIListView.au3> #include <WinAPI.au3> $h_GUI = GUICreate("Test", 200, 200, 350, 350) $h_LV = GUICtrlCreateListView("Col 1|Col 2|Col 3", 0, 0, 200, 200) _GUICtrlListView_AddItem($h_LV, "") _GUICtrlListView_AddSubItem($h_LV, 0, "bla0", 0) _GUICtrlListView_AddSubItem($h_LV, 0, "bla0", 1) _GUICtrlListView_AddSubItem($h_LV, 0, "bla0", 2) _GUICtrlListView_AddItem($h_LV, "") _GUICtrlListView_AddSubItem($h_LV, 1, "bla1", 0) _GUICtrlListView_AddSubItem($h_LV, 1, "bla1", 1) _GUICtrlListView_AddSubItem($h_LV, 1, "bla1", 2) _GUICtrlListView_AddItem($h_LV, "") _GUICtrlListView_AddSubItem($h_LV, 2, "bla2", 0) _GUICtrlListView_AddSubItem($h_LV, 2, "bla2", 1) _GUICtrlListView_AddSubItem($h_LV, 2, "bla2", 2) _GUICtrlListView_AddItem($h_LV, "") _GUICtrlListView_AddSubItem($h_LV, 3, "bla3", 0) _GUICtrlListView_AddSubItem($h_LV, 3, "bla3", 1) _GUICtrlListView_AddSubItem($h_LV, 3, "bla3", 2) $h_LV_NewWndProc = DllCallbackRegister("WndProc_LV", "int", "hwnd;uint;wparam;lparam") $g_LV_OldWndProc = _WinAPI_SetWindowLong(GUICtrlGetHandle($h_LV), $GWL_WNDPROC, DllCallbackGetPtr($h_LV_NewWndProc)) GUISetState(@SW_SHOW) Func WndProc_LV($hWnd, $uMsg, $wParam, $lParam) Return _WinAPI_CallWindowProc($g_LV_OldWndProc, $hWnd, $uMsg, $wParam, $lParam) EndFunc ;==>WndProc_GUI Do Until GUIGetMsg() = $GUI_EVENT_CLOSE DllCallbackFree($h_LV_NewWndProc) As you can see I'm doing nothing in the WndProc of the listview. I'm simply calling the original WndProc. This still "freezes" when I mess with the width of the columns or in the original project when I add more items that they don't fit in the listview and I have to scroll. If I don't do that it's working fine.
×
×
  • Create New...