Jump to content

Recommended Posts

Posted

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.

Posted

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

Posted

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.

Posted (edited)

Hi.

For get selected item from Listview you can use:

_GUICtrlListView_GetSelectedIndices($List1)
Edited by Sh3llC043r
[size="5"] [/size]
Posted

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.

  • Moderators
Posted

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

 

Posted (edited)
Posted

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.

Posted (edited)

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
Posted (edited)

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
Posted

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.

  • 2 years later...
Posted

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

  • 8 years later...
Posted

I know this post is old, I came across is since I was looking for a solution to change the color of the items. I am creating the items with _GUICtrlListView_AddArray in most places in my program.. and manipulating the data by inserting new rows, deleting rows etc. So the UDF is a good option. The only way I could solve this problem was to recreate the items with the native GUICtrlCreateListItem and then use the _GUICtrlListView_GetItemParam to retreive the control ID.

I hope this helps somebody who is also looking for the same answer. I dont know if there is a better way to do this.. But for me it works.

 

;Color the listview
Func _GUICtrlListView_SetItemBkColor($hWnd, $Item_index, $Color_RGB)

   ;Assign ControlIDs to the ListView Items
   $cnt = _GUICtrlListView_GetItemCount($hWnd)
   Local $data[$cnt]

   For $i = 0 to $cnt-1
      $data[$i] = _GUICtrlListView_GetItemTextString($hWnd, $i)
   Next

   _GUICtrlListView_DeleteAllItems($hWnd)

   For $i = 0 to $cnt-1
      GUICtrlCreateListViewItem($data[$i], $hWnd)
   Next

   $ctrlID = _GUICtrlListView_GetItemParam($hWnd, $Item_index)
   GUICtrlSetBkColor($ctrlID, $Color_RGB)
EndFunc   ;==>_GUICtrlListView_SetItemBkColor

 

  • 2 years later...
Posted
#include <GuiListView.au3>
_GUICtrlListView_MapIndexToID ( $hWnd, $iIndex )

I know the post is old, but seeming as it was within the top 3 results on Google when I looked into this, I felt this needs to be in here.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...