Jump to content
Sign in to follow this  
Jdop

Getting the Control ID of an existing Listview item

Recommended Posts

Jdop

For some reason this is escaping me.

The ControlID is created when GUICtrlCreateListViewItem() is called. No problem.

I want to go back later in the code , after some manipulations to the listview, and change the text color on individual items.

I can't seem to find how to retrieve the controlID programmatically when listview position is known. I need the controlID in order to change the color.

I'm quite sure this can be done, but not having any luck divining the method.

Share this post


Link to post
Share on other sites
Beege

I'm confused. Why can't you use the ctrlID returned from GUICtrlCreateListViewItem()?

Share this post


Link to post
Share on other sites
Jdop

1) I'd have to store it for later use and there are multiple items (20 or 30)

2) I delete items from the original array, so I'd have to manipulate the stored pointers , adding to the complexity.

There should be a way of getting the current controlID of a listitem.

Share this post


Link to post
Share on other sites
Fire

Hi.

For get selected item from Listview you can use:

_GUICtrlListView_GetSelectedIndices($List1)
Edited by Sh3llC043r

[size="5"] [/size]

Share this post


Link to post
Share on other sites
Jdop

Dont think so Sh3llC043r, I need the control ID not the index within the list.

I thought this would be a simple one, guess not.

Share this post


Link to post
Share on other sites
Melba23

Jdop,

Does this UDF help any? :mellow:

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

Share this post


Link to post
Share on other sites
Jdop

Jdop,

Does this UDF help any? :mellow:

M23

I thought that might be of help but it's overkill for my question and has some bugs when I tried to run it.

Must be a way to easily retrieve the existing controlID of a listview item.

Share this post


Link to post
Share on other sites
wraithdu

Really, no one knows this? Here ya go:

#NoTrayIcon
#include <GuiListView.au3>

$gui = GUICreate("lvtest")
$lv = GUICtrlCreateListView("column 1", 10, 10, 200, 200)
ConsoleWrite("listview id: " & $lv & @CRLF & @CRLF)
For $i = 1 To 10
    ConsoleWrite("item" & $i & " id: " & GUICtrlCreateListViewItem("item" & $i, $lv) & @CRLF)
Next
$hlv = GUICtrlGetHandle($lv)
ConsoleWrite(@CRLF & "hlv: " & $hlv & @CRLF & @CRLF & "================" & @CRLF)
For $i = 0 To _GUICtrlListView_GetItemCount($hlv) - 1
    ConsoleWrite("item" & $i + 1 & " param: " & _GUICtrlListView_GetItemParam($hlv, $i) & @CRLF)
Next
Edited by wraithdu

Share this post


Link to post
Share on other sites
Jdop

I actually figured it out (I forget exactly how, probably looking at some of the code references posted here) last night , but you are quite correct, _GUICtrlListView_GetItemParam is the answer.

It's one of those things , that if you don't work with the language all the time, you forget about, and it's not really intuitive based on the help file or the name.

"Retrieves the application specific value of the item "

Well, maybe you can figure out that means ControlID, but it's not all that clear.

Thanks for all the input guys.

Edited by Jdop

Share this post


Link to post
Share on other sites
wraithdu

Yeah, it's not something any random person would know. I figured one of the other 'old timers' would have known this trick.

I figued it out while working with the sorting functions for UDF created listview items. You have to specify the 'param' yourself or the sorting doesn't work. It's also where AutoIt stores it's 'control ID' for listview items. In real win32, listview items don't have control IDs. It's just an internal AutoIt thing so it can manage them for you.

Share this post


Link to post
Share on other sites
LeCarre

Indeed I had this issue.

I store the ControlID's in an array, but after sorting...

Created ID's After Sorting ID's

10 12

11 10

12 11

Clicking on the 1st ListView Item (after sorting) Returns Index of 1, my array containing ID's has a value of 10 in the first position.

There is no way to use my array to find the CntrlID of the clicked item

_GUICtrlListView_GetItemParam did the trick. But I felt compelled to explain how I fell into this rut

Still wondering why there is not Internal Answer, but having to goto UDF's for this...

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  

×