Listview drag and drop event

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
duffym
Posts: 2
Joined: 26 May 2023, 14:49

Listview drag and drop event

Post by duffym » 26 May 2023, 14:55

I am new to AHK v2 but have used v1 for a few years.

I am having difficulty understanding how listview drag and drop events are handled in v2. I understand (and like) how "OnEvent" is used in v2, but from looking at the help files I can't work out how to detect a drag/drop event (i.e. moving rows around via mouse). In the help text it refers to detection of "other" events via "OnNotify" but I have to admit I'm rather lost.

I would be grateful if anyone could provide a hint as to how I might go about this in v2.

Many thanks

Mike

just me
Posts: 9458
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Listview drag and drop event

Post by just me » 28 May 2023, 06:27

Related to A_EventInfo = D

Code: Select all

MainGui := Gui( , "ListView")
MainLV := MainGui.AddListView("w400 r20", ["Col 1", "Col 2", "Col 3"])
Loop 10
   MainLV.Add("", A_Index . "1",A_Index . "2", A_Index . "3")
MainLV.OnNotify(-109, LVN_BEGINDRAG)
MainGui.Show()

LVN_BEGINDRAG(LV, LPARAM) {
   Row := NumGet(LPARAM + (A_PtrSize * 3), "Int") + 1 ; 1-based row number
   MsgBox("You started to drag row " . Row)
}

duffym
Posts: 2
Joined: 26 May 2023, 14:49

Re: Listview drag and drop event

Post by duffym » 28 May 2023, 11:37

Thank you @just me , that's very helpful.

I've belatedly realised that 'begindrag' is just part of the solution, and that I've been using a third party library by Pulover called LV_Rows to determine the drop target. However this library is for v1 and - so far as I can tell - isn't one of those that have already been converted to v2. I have had a stab at converting its ".drag" function myself, however this level of code is rocket science to me, and outside reasonable scope for a request for help on this forum, particularly given that drag/drop is a bit niche.

I'm still interested in using AHK v2 though and will apply drag/drop in my code if or when another third party library around listviews is published.

Best wishes

Mike

Post Reply

Return to “Ask for Help (v2)”