C# Copy/Move item from listview1 to listview2 with quantity


I would like to know how do I copy the double-click item from <strong>listview1</strong> to <strong>listview2</strong>, so far I had using this code on <strong>listview1</strong> mouse double click event.

foreach (ListViewItem item in lvItemlist.SelectedItems) { lvItemBuy.Items.Add((ListViewItem)item.Clone()); }

When I double click on the item its copy everything about the selected item to my <strong>listview2</strong>, anyway this is not really what i want..lets say in my <strong>listview1</strong> I got this item:


What I want is everytime I double-click on the item on <strong>listview1</strong>, the quantity should decrease by 1, so it will be like this on listview1:


then added the selected item to <strong>listview2</strong> with 1 quantity like this:


After double click again on the same item, it do the same thing on <strong>listview1</strong> but i dont want it to duplicate the item on <strong>listview2</strong>. Simply just +1 the quantity. Is there a way to do this?


There are many ways to do this. You can introduce Id's for the listviewItems. Don't close the ListViewItem direct, instead write a method which copies the properties from the first listviewitem to the second one. In this method you can decrease the quantity and check if the selected listviewitem is already in the second listview


There are two different different ways.

If you want to copy the items from listview1 to listview2:

private static void CopySelectedItems(ListView source, ListView target) { foreach (ListViewItem item in source.SelectedItems) { target.Items.Add((ListViewItem)item.Clone()); } }

If you want to move the items from listview1 to listview2:

private static void MoveSelectedItems(ListView source, ListView target) { while (source.SelectedItems.Count > 0) { ListViewItem temp = source.SelectedItems[0]; source.Items.Remove(temp); target.Items.Add(temp); } }


  • How do I include a single-quote in MSBuild item transformation seperator?
  • ProgressBar In Windows phone 7?
  • combination of smote and undersampling on weka
  • What to look for when setting UpdateBatchSize
  • c# parsing xml with and apostrophe throws exception
  • mysqli_result::free increase php memory usage
  • Suspending event listeners
  • AngularJS : transclude ng-repeat inside directive
  • Recursion in ASP.NET Core Razor views
  • Simplify where clause with repeated associated type restrictions
  • Deduce parent class of inherited method in C++
  • How to open html table in xls on click of a button
  • For loop with if condition on multiple R functions
  • Image map in Flex
  • Who propagate bugfixes across branches (corporate development)?
  • Hide HTML elements without javascript, only CSS
  • ListItem.Attributes.Add not working
  • MySQL Order by column = x, column asc?
  • Grails calculated field in SQL
  • Get history of file changes from TFS to implement custom “blame”-behaviour of exceptions
  • Transactional Create with Validation in ServiceStack Redis Client
  • Abort upload large uploads after reading headers
  • How to define and use opencv mat of user type
  • Cassandra Data Model
  • php design question - will a Helper help here?
  • VB.net deserialize, JSON Conversion from type 'Dictionary(Of String,Object)' to type '
  • Data Validation Drop Down Box Arrow Disappearing
  • How to delete a row from a dynamic generate table using jquery?
  • json Serialization in asp
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • Angular 2 constructor injection vs direct access
  • Getting Messege Twice Using IMvxMessenger
  • Java static initializers and reflection
  • How to stop GridView from loading again when I press back button?
  • Android Google Maps API OnLocationChanged only called once
  • UserPrincipal.Current returns apppool on IIS
  • Python/Django TangoWithDjango Models and Databases
  • How to push additional view controllers onto NavigationController but keep the TabBar?
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How do I use LINQ to get all the Items that have a particular SubItem?