【问题标题】:how to copy selected rows from one wpf datagrid to another wpf datagrid? [closed]如何将选定的行从一个 wpf 数据网格复制到另一个 wpf 数据网格? [关闭]
【发布时间】:2016-04-16 21:30:28
【问题描述】:

将行从一个 WPF datagrid1 复制到另一个 wpf datagrid2

我想将选定的行从 wpf 一个 datagrid1 复制到另一个 wpf datagrid2。 [在上传的图像中,我以窗口形式应用程序完成了这个概念。 但现在我想要它在 wpf 窗口中。

如图所示,首先选择要复制的 datagrid1 中不同记录的复选框,然后在复制按钮上复制另一个 datagrid2 中的选定行,并添加一个附加列 Quantity .in 数量列,然后我手动添加新值

【问题讨论】:

  • 我的 xml 回复:<question quality='gimme teh codez'><actions><donvote/><votetoclose/></actions></question>
  • 欢迎来到 StackOverflow。请咨询stackoverflow.com/help/how-to-ask

标签: c# wpf xaml datagrid


【解决方案1】:

使用 WPF,您应该从您的第一个绑定集合中删除 SelectedItems 并将它们添加到您的第二个绑定集合...查看 MVVM、ObservableCollection、ICommand、Binding、DataContext

编辑: 只是我的想法

视图模型

public ObservableCollection<MyEntity> MySelectionCollection {get;set;}
public ObservableCollection<MyEntity> MyQuantityCollection {get;set;}
public DelegateCommand<IList> MyAddCommand {get;set;}


private void MyAddCommandExecute(IList items)
{
  //remove from MySelectionCollection 
  //add to MyQuantityCollection 
}

查看

<DataGrid x:Name="SelectionGrid" ItemsSource="{Binding MySelectionCollection }"/>

<DataGrid ItemsSource="{Binding MyQuantityCollection }"/>


<Button Content="Add" Command="{Binding MyAddCommand}" 
        CommandParameter="{Binding ElementName=SelectionGrid,Path=SelectedItems}"/>

【讨论】:

  • 没有完整的xml和C#代码你怎么敢回复? :-)
猜你喜欢
  • 1970-01-01
  • 2019-03-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-16
相关资源
最近更新 更多