Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[solved] which column is clicked in listview


  • Please log in to reply
6 replies to this topic
bwhatch2
  • Members
  • 2 posts
  • Last active: Nov 27 2011 10:34 PM
  • Joined: 27 Nov 2011
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?

Tilter_of_Windmills
  • Members
  • 323 posts
  • Last active: Apr 08 2012 01:26 PM
  • Joined: 23 Mar 2012
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!
Thank you! <---In case I forget to say it. :)

Leef_me
  • Moderators
  • 8510 posts
  • Last active: Sep 10 2015 05:50 AM
  • Joined: 08 Apr 2009
If you are are asking about "which column header"
<!-- 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; ....



garry
  • Spam Officer
  • 3219 posts
  • Last active: Sep 20 2018 02:47 PM
  • Joined: 19 Apr 2005
some old ahk_basic listview examples ( see first example )
http://www.autohotke...26&hilit=column

just me
  • Members
  • 1496 posts
  • Last active: Nov 03 2015 04:32 PM
  • Joined: 28 May 2011
Hi garry, good old AHK_Basic handcraft! :wink:

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;
*/

Prefer ahkscript.org for the time being.


bwhatch2
  • Members
  • 2 posts
  • Last active: Nov 27 2011 10:34 PM
  • Joined: 27 Nov 2011
FANTASTIC! that'll do what i need. thanks a bunch for the help

garry
  • Spam Officer
  • 3219 posts
  • Last active: Sep 20 2018 02:47 PM
  • Joined: 19 Apr 2005
@just me, thank you for your script