【问题标题】:Copy a row from one ListView to another将一行从一个 ListView 复制到另一个
【发布时间】:2019-02-18 01:15:27
【问题描述】:

所以这是我的问题。我想将特定行值从 listView 复制到另一个。例如;

listview1               listview2
Product   Price         Product   Price   QTY
Apple       5
Orange      5

然后当我按下“Apple”时,它会复制到 listview2,就像这样;

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

我也在使用点击事件。蒂亚!

【问题讨论】:

  • 您的目标是什么:Winforms、WPF、ASP..?您应该始终正确标记您的问题,以便人们可以在问题页面上看到它! - 为什么它被标记为“Javascript”?
  • 我很抱歉。我是堆栈溢出的新手,直到现在我才知道它是如何工作的。
  • 欢迎您!越遵守规则,就越有可能得到好的答案。在这里,我们希望看到 Click 事件..
  • 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 先生,您刚刚救了我的命!谢谢先生,我今天学到了很多。

标签: c# winforms listview


【解决方案1】:

TaW 解决了我的问题。这是解决方案。

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()); 
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-09
    • 2016-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-06
    • 1970-01-01
    相关资源
    最近更新 更多