[Class] LV_Rows - Copy, Cut, Paste and Drag ListViews (Updated 03/17/2016)

Post your working scripts, libraries and tools
User avatar
Pulover
Posts: 365
Joined: 29 Sep 2013, 19:51
Location: Brazil
Contact:

[Class] LV_Rows - Copy, Cut, Paste and Drag ListViews (Updated 03/17/2016)

04 Oct 2013, 07:22

This class is a collection of functions to allow additional features in ListViews that are not supported by AutoHotkey built-in functions.
It provides an easy way to add the commands Copy, Cut, Paste, DuplicateDelete, Move, Drag, Undo and Redo.

Features:
  • Edit functions: Copy, Cut, Paste, Duplicate, Delete, Move, Drag, CopyTo and MoveTo.
  • History functions: Add, Undo and Redo.
  • Group functions: EnableGroups, InsertGroup, RemoveGroup, InsertAtGroup, RemoveAtGroup, SetGroups, GetGroups, SetGroupCollapisable, RemoveAllGroups, CollapseAll and RefreshGroups.
  • Copy, cut and paste between different ListViews.
  • Keep history of individual ListViews to be used with Undo and Redo.
  • Drag-and-Drop shows a destination bar to indicate where selected rows will be moved to.
  • Auto-Scrolls ListViews when dragging above or below them.
  • Easily add and manage ListView Groups.
  • Supports Right-Click drag.
  • Supports Checked ListViews.
  • Supports ListViews with Icons.
  • Customize Auto-Scroll delay, thickness and color of destination bar.

Screenshots:
Spoiler

Notes:
  • They all operate on the active ListView control, like AHK built-in functions.
  • Edit functions can be called directly as easy as ^c::LV_Rows.Copy() (except CopyTo and MoveTo that need to be initialized with a HWND).
  • History and Group functions must be initialized via Handle := New LV_Rows().
  • To keep original icons you must initialize it passing the ListView's HWND, e.g. Handle := New LV_Rows(Hwnd).
  • The Drag function must be called from the LV G-Label when the Drag event occurs.
  • You can manage multiple listviews with the same Handle.
  • Pass the HWND's in inialization, e.g. Handle := New LV_Rows(Hwnd1, Hwnd2, Hwnd3...) and use SetHwnd() to select them.
  • Use SetHwnd() or InsertHwnd() to add more HWND's to the Handle.

:arrow: Sources, documentation and examples on GitHub

Special thanks to Micahs for the base code for the Drag function and to just me for the LV_EX library used for the Group functions.
Last edited by Pulover on 17 Mar 2016, 06:19, edited 5 times in total.
Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer)
doomboy1000
Posts: 1
Joined: 24 Dec 2013, 19:20

Re: [Class] LV_Rows - Copy, Cut, Paste and Drag ListViews

24 Dec 2013, 19:31

Both this code (Dec 24, 2013) and the version hosted on the other forums seem to have some problems for me in AHK_L 1.1.10.01.

Specifically,
~Line 188:

Code: [Select all] [Download] (Class_LV_Rows.ahk)GeSHi © Codebox Plus

, DupRows.Paste(, False)

Yields an error about not allowing a blank parameter. Perhaps it should be

Code: [Select all] [Download] (Class_LV_Rows.ahk)GeSHi © Codebox Plus

, DupRows.Paste("", False)


Then, trying to drag a row yields an error, in which it seems the variable Line_W is never defined; the custom Gui Element "MarkLine" is given an unknown parameter "W H2 Y327 X278 NoActivate" (notice the W number is blank). I'm not sure where the root of this is happening, though.

Thanks for the great class!

EDIT: It seems the line

Code: [Select all] [Download] (Class_LV_Rows.ahk)GeSHi © Codebox Plus

LV_lw := LV_lw * 96 / A_ScreenDPI

Is causing a problem because A_ScreenDPI is not defined. Must this be done manually, or is this a feature of a newer AHK_L (or other fork)?
User avatar
Pulover
Posts: 365
Joined: 29 Sep 2013, 19:51
Location: Brazil
Contact:

Re: [Class] LV_Rows - Copy, Cut, Paste and Drag ListViews

24 Dec 2013, 19:42

Hi,
Please, update AutoHotkey to the latest version and try it again.

Thanks for the feedback.
Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer)
User avatar
hoppfrosch
Posts: 267
Joined: 07 Oct 2013, 04:05
GitHub: hoppfrosch
Location: Rhine-Maine-Area, Hesse, Germany
Contact:

Re: [Class] LV_Rows - Copy, Cut, Paste and Drag ListViews

24 Apr 2014, 01:01

EDIT: Now it works as expected - strange .... Perhaps web wasn't very responsive at the time the problem occured ...

-----------------------

Hmmmmm ... cannot access the code you posted in your initial post.

Clicking on buttons "Spoiler -> SHOW", an "EXPAND" button occurs (which is unfamiliar, as "expand" is usually part of the Codebox header...) - clicking on the "EXPAND" button nothing happens (it toggles to "COLLAPSE-Button and vice versa)....

2014-04-24 07_56_33-[Class] LV_Rows - Copy, Cut, Paste and Drag ListViews • AHKScript.png
What it looks like ....
2014-04-24 07_56_33-[Class] LV_Rows - Copy, Cut, Paste and Drag ListViews • AHKScript.png (8.78 KiB) Viewed 3860 times
m3user
Posts: 92
Joined: 17 Jan 2014, 18:11

Re: [Class] LV_Rows - Copy, Cut, Paste and Drag ListViews

04 May 2014, 09:10

Is anything like this available for TreeView?
User avatar
Pulover
Posts: 365
Joined: 29 Sep 2013, 19:51
Location: Brazil
Contact:

Re: [Class] LV_Rows - Copy, Cut, Paste and Drag ListViews

04 May 2014, 09:21

Not yet, AFAIK.
Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer)
User avatar
Chef
Posts: 50
Joined: 14 Nov 2013, 13:01

Re: [Class] LV_Rows - Copy, Cut, Paste and Drag ListViews

20 Jun 2014, 04:01

Any reason why your not using LVM to do all the work? Using built-in functions for listviews makes it impossible to use.
User avatar
Pulover
Posts: 365
Joined: 29 Sep 2013, 19:51
Location: Brazil
Contact:

Re: [Class] LV_Rows - Copy, Cut, Paste and Drag ListViews

20 Jun 2014, 05:06

Chef wrote:Any reason why your not using LVM to do all the work?

Yes. I made this class based on functions and routines I had already for my app. It was easier and faster to use built-in functions, since they work pretty well.

Chef wrote:Using built-in functions for listviews makes it impossible to use.

I don't get your point. I can do everything I need with it.
If you want to create a version based on LVM, you're free to do it and post it or link it here, I don't have the time or interest to rebuild the class with it.
Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer)
think
Posts: 27
Joined: 09 Feb 2014, 05:20

Re: [Class] LV_Rows - Copy, Cut, Paste and Drag ListViews

16 Aug 2014, 09:20

Great class, thank you. Would it be possible to drag/drop items between tabs?
User avatar
Pulover
Posts: 365
Joined: 29 Sep 2013, 19:51
Location: Brazil
Contact:

Re: [Class] LV_Rows - Copy, Cut, Paste and Drag ListViews

16 Aug 2014, 09:43

think wrote:Great class, thank you. Would it be possible to drag/drop items between tabs?

Thanks. I've tried to do that for PMC but went into many issues... You can try to implement it yourself, I don't think you need to change anything in the class.
Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer)
garry
Posts: 885
Joined: 22 Dec 2013, 12:50

Re: [Class] LV_Rows - Copy, Cut, Paste and Drag ListViews

17 Aug 2014, 02:55

Hello Pulover, works fine

Want ask you , how to manage a csv-file =

-Delete one/multiple selected row
-Modify
-Add-New
-Move-UP
-Move-Down
-Search and then delete or modify
-DoubleClick > run selected column (example c2)


example, see F1 ( csv-file )
( example reads variable e4x )

Code: [Select all] [Expand] [Download] (Script.ahk)GeSHi © Codebox Plus

think
Posts: 27
Joined: 09 Feb 2014, 05:20

Re: [Class] LV_Rows - Copy, Cut, Paste and Drag ListViews

10 Sep 2014, 14:58

Hi, I have one more question. In my script I use few ListViews in different tabs so I keep history of each ListView using different handles. Sometimes I move the content of one ListView to another. Is it possible to assign/move the history from one handle to another? Thanks.

Code: [Select all] [Download] (Script.ahk)GeSHi © Codebox Plus

History1 := New LV_Rows()
History1.Add()
; ...
History2 := New LV_Rows()
History2.Add()
; ...
; how to assign History1 to History2?
User avatar
Pulover
Posts: 365
Joined: 29 Sep 2013, 19:51
Location: Brazil
Contact:

Re: [Class] LV_Rows - Copy, Cut, Paste and Drag ListViews

10 Sep 2014, 16:26

think wrote:Hi, I have one more question. In my script I use few ListViews in different tabs so I keep history of each ListView using different handles. Sometimes I move the content of one ListView to another. Is it possible to assign/move the history from one handle to another? Thanks.

Code: [Select all] [Download] (Script.ahk)GeSHi © Codebox Plus

History1 := New LV_Rows()
History1.Add()
; ...
History2 := New LV_Rows()
History2.Add()
; ...
; how to assign History1 to History2?

Well, you could try History2 := History1. ;)
Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer)
think
Posts: 27
Joined: 09 Feb 2014, 05:20

Re: [Class] LV_Rows - Copy, Cut, Paste and Drag ListViews

12 Sep 2014, 15:19

Of course... It didn't work at first as I had other issues... Thanks.
highend
Posts: 43
Joined: 24 Nov 2014, 16:57

Re: [Class] LV_Rows - Copy, Cut, Paste and Drag ListViews

20 Sep 2015, 11:15

Everything works just fine until... I create a new window with e.g. Gui, New, , testwindow
right before the Gui, Add, ListView line

When I do that, all the context menus stop working (they don't do anything anymore)

I can't find out what to change in the code to get it working again *sigh*

Any help would be appreciated :)
User avatar
Pulover
Posts: 365
Joined: 29 Sep 2013, 19:51
Location: Brazil
Contact:

Re: [Class] LV_Rows - Copy, Cut, Paste and Drag ListViews

16 Mar 2016, 19:58

Update:
  • Added support for multiple ListView hwnd's in the same handle.
  • Added ListView Groups functions (thanks to just me).
Now you can use the same Handle to manage different ListViews, keeping individual history but sharing copied data. The documentation can be found on GitHub too.
All original behavior was kept, so updating shouldn't break any script.
Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer)
gr81

Re: [Class] LV_Rows - Copy, Cut, Paste and Drag ListViews

16 Mar 2016, 20:39

Your class as is doesn't work on my side, too many errors, I had to go through the old version and change the built-in functions (that I needed) to LVM.
You need to get rid of all built-in functions and use LVM instead.
Thanks anyway.
User avatar
Pulover
Posts: 365
Joined: 29 Sep 2013, 19:51
Location: Brazil
Contact:

Re: [Class] LV_Rows - Copy, Cut, Paste and Drag ListViews

16 Mar 2016, 21:03

gr81 wrote:Your class as is doesn't work on my side, too many errors
What errors?

gr81 wrote:You need to get rid of all built-in functions and use LVM instead.
It works for me so I'm not inclined to change that unless someone shows me a good reason.

Feel free to collaborate with the project.
Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer)
User avatar
Pulover
Posts: 365
Joined: 29 Sep 2013, 19:51
Location: Brazil
Contact:

Update v1.1.1

29 Apr 2016, 11:11

Update v1.1.1
  • Fixed collapsed groups expanded after refreshing.
Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer)
User avatar
Pulover
Posts: 365
Joined: 29 Sep 2013, 19:51
Location: Brazil
Contact:

Update v1.1.2

09 Jun 2016, 17:58

Update v1.1.2
  • Removed *CopyTo* and *MoveTo* functions due to bugs with setting target ListView.
Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer)

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 6 guests