How to copy a Listview, changing things in the copy, keeping the original

Public support forum for peer to peer support with related to the Visual Objects and Vulcan.NET products
Post Reply
ic2
Posts: 1798
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

How to copy a Listview, changing things in the copy, keeping the original

Post by ic2 »

I posted this on comp.lang, got several reactions (oClone which I never heard about, a seperate function) but all change the original listview. So in case someone missed this post and knows an alternative to copy a listview just like aClone works for arrays I post it here as well:

We show a listview in a window and use that LV variable to pass to a
method to export the contents to Excel.

Now 1 client wants to see a few of these columns omiitted in the Excel
export. It is not difficult ti remove the columns
(oLVl:DeleteColumn(2) etc) but thet should not be deleted in the
'master' listview showing in the screen.

Problem is that doing this:

oLVCopy:=oLVOriginal

and then delete the columns in oLVCopy also deletes these columns in
oLVOriginal, which is apparently copied by reference.

What would be the quickets way to copy the listview in such a way that
I can still pass it after deleting the required columns to my Excel
function without changing the original listview?

Dick
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

How to copy a Listview, changing things in the copy, keeping the original

Post by Phil Hepburn »

LINQ is your friend.

Use LINQ code to operate on the original collection to make a resultant reduced (in columns) collection.

Get back to me with more specific information if you need help.

What collection have you got bound to your listview ?

Cheers,
Phil.
P.S. all of this stuff is in the free to download eNotes from the Forums documentation.
ic2
Posts: 1798
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

How to copy a Listview, changing things in the copy, keeping the original

Post by ic2 »

Sorry Phil,

It was a VO question. So Linq won't help. And collections are not VO either.

I can solve it in many ways, just copying the LV without it modifying the original would costs me by far the least time.

Dick
User avatar
Chris
Posts: 4562
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

How to copy a Listview, changing things in the copy, keeping the original

Post by Chris »

Hi Dick,

I think the quickest solution is what Franz posted in clcvo, just create an emtpy new one and copy the data you need only.

Although personally I would change the approach and not depend on a GUI item (ListView) for storing and passig the data, but use an intermediate array instead.

Chris
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
ic2
Posts: 1798
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

How to copy a Listview, changing things in the copy, keeping the original

Post by ic2 »

Hello Chris,

Although personally I would change the approach and not depend on a GUI item (ListView) for storing and passing the data, but use an intermediate array instead.

You are of course right in there. I think I was so concentrated on adapting the current routine that I hardly realized it's not the best way to solve it :unsure:

One of my employees who wrote this LV->Excel years ago told me today she also wrote a function to remove columns from the multi-dimensional array we create from this LV and always use to export to Excel.

This worked nearly the same, just a bit further up in the program, and is more elegant.

Thanks for your comments!

Dick
User avatar
Chris
Posts: 4562
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

How to copy a Listview, changing things in the copy, keeping the original

Post by Chris »

You're welcome, glad you've already got a nice solution!

Chris
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
Post Reply