简体   繁体   English

将行添加到 wpf 数据网格

[英]Adding rows to wpf datagrid

I need to select a set of rows from one wpf toolkit datagrid and want to add it in another wpf toolkit datagrid.我需要从一个 wpf 工具包数据网格中选择一组行,并希望将其添加到另一个 wpf 工具包数据网格中。 The code I used is as follows:我使用的代码如下:

foreach(DataRowView row in MyFirstDataGrid.SelectedItems)
{
  MySecondDataGrid.Items.Add(row);
}

But the problem here is, it just adds empty rows in the second datagrid without any contents.... Can anyone please help me in this issue????但这里的问题是,它只是在没有任何内容的第二个数据网格中添加了空行......任何人都可以帮我解决这个问题吗????

Thanks and Regards, Suba.谢谢和问候,苏巴。

Are the grids bound?网格是绑定的吗? Could you just add it to the second grid's item source?你能把它添加到第二个网格的项目源吗?

I think even if you defined the same columns, it doesn't just work if you add the rows to the second datagrid.我认为即使您定义了相同的列,如果您将行添加到第二个数据网格,它也不会起作用。 instead, if both grids have an ItemsSource of the same type, add it to the itemsSource of the second grid.相反,如果两个网格都有相同类型的 ItemsSource,请将其添加到第二个网格的 itemsSource。 Should work if it's an ObservableCollection.如果它是 ObservableCollection 应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM