-3

So this is my problem. I want to copy a specific row value from listView to another. For example;

listview1               listview2
Product   Price         Product   Price   QTY
Apple       5
Orange      5

then when I press "Apple" it will copy to listview2, like this;

listview1               listview2
Product   Price         Product   Price   QTY
Apple       5           Apple       5
Orange      5

Also I'm using click event. TIA!

Alex Myers
  • 6,196
  • 7
  • 23
  • 39
noob coder
  • 29
  • 2
  • What are you targetting: Winforms, WPF, ASP..? YOU should __always__ TAG your questions correctly so one can see it on the questions page! - Why is it tagged 'Javascript'? – TaW Sep 13 '18 at 10:10
  • 1
    I'm so sorry. I'm new to stack overflow, I don't know how it works until now. – noob coder Sep 13 '18 at 10:11
  • Welcome! The betterto follow the rules the more likely good answers will be. Here we'd like to see that Click event.. – TaW Sep 13 '18 at 10:16
  • 2
    Winforms: `private void listView1_MouseClick(object sender, MouseEventArgs e) { if (listView1.SelectedItems.Count < 1) return; var item = listView1.SelectedItems[0]; listView2.Items.Add( (ListViewItem) item.Clone()); }` – TaW Sep 13 '18 at 11:13
  • 1
    @TaW Sir you have just saved my life! Thanks Sir I learned so much today. – noob coder Sep 13 '18 at 11:31

1 Answers1

2

TaW solved my problem. Here is the solution.

private void listView1_MouseClick(object sender, MouseEventArgs e)
{
   if (listView1.SelectedItems.Count < 1) return; 
   var item = listView1.SelectedItems[0]; 
   listView2.Items.Add( (ListViewItem) item.Clone()); 
}
TaW
  • 53,122
  • 8
  • 69
  • 111
noob coder
  • 29
  • 2