i can't for the life of me figure out how to get which column ive clicked on in a list view. i can get the row and other info but not which column was clicked on. im sure im missing something obvious. any help?

[solved] which column is clicked in listview
Started by
bwhatch2
, May 07 2012 02:07 AM
6 replies to this topic
#1
-
Posted 07 May 2012 - 02:07 AM
![[solved] which column is clicked in listview: post #1](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)
It is the nature of a listview that when you click in it, you are selecting a row, not a column. You can get the column information from the row you have selected with LV_GetText(). Why would you need the column number? Show a bit of your code so that we can see what you are attempting to do, please.
Side note: Wow. I admire your restraint.
You joined in 2011 and have waited until now to post!
Side note: Wow. I admire your restraint.

#2
-
Posted 07 May 2012 - 03:03 AM
![[solved] which column is clicked in listview: post #2](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)
Thank you! <---In case I forget to say it.

If you are are asking about "which column header"
<!-- m -->http://www.autohotke... ... htm#notify<!-- m -->
<!-- m -->http://www.autohotke... ... htm#notify<!-- m -->
ColClick: The user has clicked a column header. The variable A_EventInfo contains the column number, which is the original number assigned when the column was created; ....
#3
-
Posted 07 May 2012 - 04:43 AM
![[solved] which column is clicked in listview: post #3](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)
#4
-
Posted 07 May 2012 - 06:15 AM
![[solved] which column is clicked in listview: post #4](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)
Hi garry, good old AHK_Basic handcraft! :wink:
Some alternative:
Some alternative:
#NoEnv Gui, Margin, 20, 20 Gui, Add, ListView, w400 r9 Grid HwndHLV1 gSubLV AltSubmit, Column 1|Column 2|Column 3 Loop, 9 LV_Add("", A_Index, A_Index, A_Index) Loop, 3 LV_ModifyCol(A_Index, "AutoHdr") Gui, Show, , ListView Return ; ---------------------------------------------------------------------------------------------------------------------- GuiCLose: ExitApp ; ---------------------------------------------------------------------------------------------------------------------- SubLV: If (A_GuiEvent = "Normal") { Row := A_EventInfo Column := LV_SubItemHitTest(HLV1) ToolTip, You clicked on column %Column% in row %Row%! SetTimer, KillToolTip, -1500 } Return ; ---------------------------------------------------------------------------------------------------------------------- KillToolTip: ToolTip Return ; ---------------------------------------------------------------------------------------------------------------------- LV_SubitemHitTest(HLV) { ; To run this with AHK_Basic change all DllCall types "Ptr" to "UInt", please. ; HLV - ListView's HWND Static LVM_SUBITEMHITTEST := 0x1039 VarSetCapacity(POINT, 8, 0) ; Get the current cursor position in screen coordinates DllCall("User32.dll\GetCursorPos", "Ptr", &POINT) ; Convert them to client coordinates related to the ListView DllCall("User32.dll\ScreenToClient", "Ptr", HLV, "Ptr", &POINT) ; Create a LVHITTESTINFO structure (see below) VarSetCapacity(LVHITTESTINFO, 24, 0) ; Store the relative mouse coordinates NumPut(NumGet(POINT, 0, "Int"), LVHITTESTINFO, 0, "Int") NumPut(NumGet(POINT, 4, "Int"), LVHITTESTINFO, 4, "Int") ; Send a LVM_SUBITEMHITTEST to the ListView SendMessage, LVM_SUBITEMHITTEST, 0, &LVHITTESTINFO, , ahk_id %HLV% ; If no item was found on this position, the return value is -1 If (ErrorLevel = -1) Return 0 ; Get the corresponding subitem (column) Subitem := NumGet(LVHITTESTINFO, 16, "Int") + 1 Return Subitem } /* typedef struct _LVHITTESTINFO { POINT pt; UINT flags; int iItem; int iSubItem; int iGroup; } LVHITTESTINFO, *LPLVHITTESTINFO; */
#5
-
Posted 07 May 2012 - 02:22 PM
![[solved] which column is clicked in listview: post #5](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)
Prefer ahkscript.org for the time being.
FANTASTIC! that'll do what i need. thanks a bunch for the help
#6
-
Posted 07 May 2012 - 05:07 PM
![[solved] which column is clicked in listview: post #6](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)